﻿namespace BEGDC.CC.Web.UserControls.OutCR
{
	using System;
	using System.Data;
	using System.Collections;
	using System.Drawing;
	using System.Text;
	using System.Web;
	using System.Web.UI.WebControls;
	using System.Web.UI.HtmlControls;

	using BEGDC.CC.BL.CCFlow.CV;
	using BEGDC.CC.BL.CCFlow.CR;
	using BEGDC.CC.Entity;
	using BEGDC.CC.BL.Workflow;
	using BEGDC.CC.BL.Common;
	using BEGDC.CC.BL.Common.Query;
	using BEGDC.Utility.Castle;
	using BEGDC.CC.BL.UserManagement;

	/// <summary>
	///	Summary description for Apply.
	/// </summary>
	public class EZCtrlForCO : BaseOutCR
	{

		#region ui control definition
		protected BEGDC.CC.Web.UserControls.Export ctrlExport;
		protected System.Web.UI.WebControls.RadioButtonList RBL_KeyMessage;
		protected System.Web.UI.WebControls.Label Lb_CISWarning;
		protected System.Web.UI.WebControls.TextBox Ctl_TravelAgency;
		protected System.Web.UI.WebControls.Label Lb_TravelAgency;
		protected System.Web.UI.WebControls.Label lbDepartmentReadOnly;
		protected System.Web.UI.WebControls.TextBox tbSomeoneName;
		protected System.Web.UI.WebControls.TextBox tbSomeoneEmail;
		protected System.Web.UI.WebControls.TextBox tbCustomerName;
		protected System.Web.UI.WebControls.RadioButtonList rbIsFCPA;
		protected System.Web.UI.WebControls.TextBox tbCustomerCountry;
		protected System.Web.UI.WebControls.RadioButtonList rbReviewGuideLine;
		protected System.Web.UI.WebControls.TextBox tbOtherLocation;
		protected System.Web.UI.WebControls.TextBox tbVisitObjectives;
		protected System.Web.UI.WebControls.CheckBoxList cblPreferredLocation;
		protected System.Web.UI.WebControls.TextBox tbPotentialRevenue;
		protected System.Web.UI.WebControls.DropDownList ddlPotentialRevenueTime;
		protected System.Web.UI.WebControls.DropDownList ddlSaleStage;
		protected System.Web.UI.WebControls.RadioButtonList rbOutStandingRFP;
		protected System.Web.UI.WebControls.TextBox tbSensitiveIssues;
		protected System.Web.UI.WebControls.TextBox tbKeyMessage;
		protected System.Web.UI.WebControls.TextBox tbCompanyProfile;
		protected System.Web.UI.WebControls.DropDownList ddlAccountType;
		protected System.Web.UI.WebControls.TextBox tbProposalNo;
		protected System.Web.UI.WebControls.RadioButtonList rbSalesContract;
		protected System.Web.UI.WebControls.RadioButtonList rbSalesContractSigned;
		protected System.Web.UI.WebControls.TextBox tbNotSalesContractDescription;
		protected System.Web.UI.WebControls.RadioButtonList rbActivityInTrip;
		protected System.Web.UI.WebControls.TextBox tbRequestedDateFrom;
		protected System.Web.UI.WebControls.TextBox tbRequestedDateTo;
		protected System.Web.UI.WebControls.TextBox tbTopic;
		protected System.Web.UI.WebControls.TextBox tbCustomerTeamHost;
		protected System.Web.UI.WebControls.TextBox tbCustomerOfficeTel;
		protected System.Web.UI.WebControls.TextBox tbCustomerFax;
		protected System.Web.UI.WebControls.TextBox tbCustomerEmail;
		protected System.Web.UI.WebControls.DropDownList ddlSalesBusinessUnit;
		protected System.Web.UI.WebControls.DropDownList ddlRegion;
		protected System.Web.UI.WebControls.TextBox tbDatesRequiredFrom;
		protected System.Web.UI.WebControls.TextBox tbDatesRequiredTo;
		protected System.Web.UI.WebControls.TextBox tbPreferEntertainment;
		protected System.Web.UI.WebControls.TextBox tbEntertainmentPriceRangeFrom;
		protected System.Web.UI.WebControls.TextBox tbEntertainmentPriceRangeTo;
		protected System.Web.UI.WebControls.RadioButtonList rbGiftNeed;
		protected System.Web.UI.WebControls.TextBox tbGiftPriceRangeFrom;
		protected System.Web.UI.WebControls.TextBox tbGiftPriceRangeTo;
		protected System.Web.UI.WebControls.RadioButtonList rbReceivedGift;
		protected System.Web.UI.WebControls.TextBox tbNotDirectReason;
		protected System.Web.UI.WebControls.TextBox tbEstimateCostPerPerson;
		protected System.Web.UI.WebControls.TextBox tbReason;
		protected System.Web.UI.WebControls.TextBox tbPreferGift;
		protected System.Web.UI.WebControls.TextBox tbEstimateTotalCost;
		protected System.Web.UI.WebControls.TextBox tbRequestorName;
		protected System.Web.UI.WebControls.TextBox tbRequestOfficeTel;
		protected System.Web.UI.WebControls.TextBox tbRequestorMobile;
		protected System.Web.UI.WebControls.TextBox tbSomeoneTel;
		protected System.Web.UI.WebControls.RadioButtonList rbEntertainmentNeed;
		protected System.Web.UI.WebControls.Literal litScript;
		protected System.Web.UI.WebControls.Label lbRequestorNameReadOnly;
		protected System.Web.UI.WebControls.Label lbRequestOfficeTelReadOnly;
		protected System.Web.UI.WebControls.Label lbRequestorMobileReadOnly;
		protected System.Web.UI.WebControls.Label lbSomeoneElseReadOnly;
		protected System.Web.UI.WebControls.Label lbSomeoneNameReadOnly;
		protected System.Web.UI.WebControls.Label lbSomeoneTelReadOnly;
		protected System.Web.UI.WebControls.Label lbSomeoneEmailReadOnly;
		protected System.Web.UI.WebControls.Label lbCustomerNameReadOnly;
		protected System.Web.UI.WebControls.Label lbIsFCPAReadOnly;
		protected System.Web.UI.WebControls.Label lbCustomerCountryReadOnly;
		protected System.Web.UI.WebControls.Label lbReviewGuideLineReadOnly;
		protected System.Web.UI.WebControls.Label lbPreferredLocationReadOnly;
		protected System.Web.UI.WebControls.Label lbOtherLocationReadOnly;
		protected System.Web.UI.WebControls.Label lbGuestNumberReadOnly;
		protected System.Web.UI.WebControls.Label lbVisitObjectivesReadOnly;
		protected System.Web.UI.WebControls.Label lbPotentialRevenueReadOnly;
		protected System.Web.UI.WebControls.Label lbPotentialRevenueTimeReadOnly;
		protected System.Web.UI.WebControls.Label lbSaleStageReadOnly;
		protected System.Web.UI.WebControls.Label lbOutStandingRFPReadOnly;
		protected System.Web.UI.WebControls.Label lbSeneitiveIssuesReadOnly;
		protected System.Web.UI.WebControls.Label lbKeyMessageReadOnly;
		protected System.Web.UI.WebControls.Label lbCompanyProfileReadOnly;
		protected System.Web.UI.WebControls.Label lbAccountTypeReadOnly;
		protected System.Web.UI.WebControls.Label lbProposalNoReadOnly;
		protected System.Web.UI.WebControls.Label lbSalesContractReadOnly;
		protected System.Web.UI.WebControls.Label lbSalesContractSignedReadOnly;
		protected System.Web.UI.WebControls.Label lbNotSalesContractDescriptionReadOnly;
		protected System.Web.UI.WebControls.Label lbActivityInTripReadOnly;
		protected System.Web.UI.WebControls.Label lbRequestedDateFromReadOnly;
		protected System.Web.UI.WebControls.Label lbRequestedDateToReadOnly;
		protected System.Web.UI.WebControls.Label lbTopicReadOnly;
		protected System.Web.UI.WebControls.Label lbCustomerTeamHostReadOnly;
		protected System.Web.UI.WebControls.Label lbCustomerOfficeTelReadOnly;
		protected System.Web.UI.WebControls.Label lbCustomerFaxReadOnly;
		protected System.Web.UI.WebControls.Label lbCustomerEmailReadOnly;
		protected System.Web.UI.WebControls.Label lbSalesBusinessUnitReadOnly;
		protected System.Web.UI.WebControls.Label lbRegionReadOnly;
		protected System.Web.UI.WebControls.Label lbDatesRequiredFromReadOnly;
		protected System.Web.UI.WebControls.Label lbDatesRequiredToReadOnly;
		protected System.Web.UI.WebControls.Label lbEntertainmentNeedReadOnly;
		protected System.Web.UI.WebControls.Label lbPreferEntertainmentReadOnly;
		protected System.Web.UI.WebControls.Label lbEntertainmentPriceRangeFromReadOnly;
		protected System.Web.UI.WebControls.Label lbEntertainmentPriceRangeToReadOnly;
		protected System.Web.UI.WebControls.Label lbGiftNeedReadOnly;
		protected System.Web.UI.WebControls.Label lbPreferGiftReadOnly;
		protected System.Web.UI.WebControls.Label lbGiftPriceRangeFromReadOnly;
		protected System.Web.UI.WebControls.Label lbGiftPriceRangeToReadOnly;
		protected System.Web.UI.WebControls.Label lbReceivedGiftReadOnly;
		protected System.Web.UI.WebControls.Label lbNotDirectReasonReadOnly;
		protected System.Web.UI.WebControls.Label lbEstimateTotalCostReadOnly;
		protected System.Web.UI.WebControls.Label lbEstimateCostPerPersonReadOnly;
		protected System.Web.UI.WebControls.Label lbReasonReadOnly;
		protected System.Web.UI.WebControls.Label lbAlternateDateFromReadOnly;
		protected System.Web.UI.WebControls.Label lbAlternateDateToReadOnly;
		protected System.Web.UI.WebControls.Label lbAppNo;
		
		protected System.Web.UI.HtmlControls.HtmlImage CustomerPaneImg;
		protected System.Web.UI.HtmlControls.HtmlImage ALPaneImg;
		protected System.Web.UI.HtmlControls.HtmlImage CostCenterPaneImg;
		//		protected System.Web.UI.HtmlControls.HtmlTableCell td_left;
		//		protected System.Web.UI.HtmlControls.HtmlTableCell td_center;
		//		protected System.Web.UI.HtmlControls.HtmlTableCell td_right;
		protected System.Web.UI.HtmlControls.HtmlTableRow tr_Title;
		protected System.Web.UI.HtmlControls.HtmlTableRow tr_Button;
		protected System.Web.UI.HtmlControls.HtmlImage ContractDateImg;
		//protected System.Web.UI.HtmlControls.HtmlImage RequestedDateFromImg;
		//protected System.Web.UI.HtmlControls.HtmlImage tbRequestedDateToImg;
		//protected System.Web.UI.HtmlControls.HtmlImage tbAlternateDateFromImg;
		//protected System.Web.UI.HtmlControls.HtmlImage tbAlternateDateToImg;
		//protected System.Web.UI.HtmlControls.HtmlImage tbDatesRequiredFromImg;
		//protected System.Web.UI.HtmlControls.HtmlImage tbDatesRequiredToImg;
		protected System.Web.UI.WebControls.RadioButtonList rbSomeoneElse;
		protected System.Web.UI.HtmlControls.HtmlGenericControl RequestedDateFromSpan;
		protected System.Web.UI.HtmlControls.HtmlGenericControl tbRequestedDateToSpan;
		protected System.Web.UI.HtmlControls.HtmlGenericControl RequestedDateFromspan;
		//protected System.Web.UI.HtmlControls.HtmlGenericControl tbDatesRequiredFromSpan;
		//protected System.Web.UI.HtmlControls.HtmlGenericControl tbDatesRequiredToSpan;
		protected System.Web.UI.WebControls.TextBox tbAlternateDateFrom;
		protected System.Web.UI.WebControls.TextBox tbAlternateDateTo;

		protected System.Web.UI.WebControls.DropDownList Dp_Department;
		protected System.Web.UI.WebControls.DataGrid dgContractInfo;
		protected System.Web.UI.HtmlControls.HtmlImage ConrtractInfoPane;
		protected System.Web.UI.WebControls.Label tx_AllDepts;
		protected System.Web.UI.WebControls.Label tx_Account;
		protected System.Web.UI.WebControls.CheckBoxList cblDomesticOversea;
		protected System.Web.UI.WebControls.Label lbDomesticReadonly;
		protected BEGDC.CC.Web.Control.UserSearchControl SearchStaff;
		protected System.Web.UI.HtmlControls.HtmlTable Table_Contract;
		protected System.Web.UI.WebControls.DataGrid dgCustomerList;
		protected System.Web.UI.WebControls.DataGrid dgALAttendee;
		protected System.Web.UI.WebControls.DataGrid dgCostCenter;
		//protected System.Web.UI.WebControls.DataGrid DG_LeaseCar;
		//protected System.Web.UI.WebControls.Label Lb_TotalPriceForLeaseCar;
		//protected System.Web.UI.HtmlControls.HtmlImage LeaseCarImg;
		protected System.Web.UI.WebControls.TextBox Ctl_RFPDetails;
		protected System.Web.UI.WebControls.Label Lb_RFPDetails;
		protected System.Web.UI.WebControls.RadioButtonList RB_IsSensitiveIssue;
		protected System.Web.UI.WebControls.TextBox Ctl_DetailedItinerary;
		protected System.Web.UI.WebControls.Label Lb_DetailedItinerary;

		//protected System.Web.UI.HtmlControls.HtmlImage HotelBookingImg;
//		protected System.Web.UI.WebControls.TextBox Ctl_MealEachCost;
		protected System.Web.UI.WebControls.Label LB_MealEachCost;
		protected System.Web.UI.WebControls.TextBox Ctl_GiftsDetails;
		protected System.Web.UI.WebControls.Label Lb_GiftDetails;
		protected System.Web.UI.WebControls.RadioButtonList RB_IsTravelAgency;
		protected System.Web.UI.WebControls.Label Lb_IsTravelAgency;
		protected System.Web.UI.WebControls.TextBox Ctl_HRID;
		protected System.Web.UI.WebControls.Label LB_HRID;
		protected System.Web.UI.WebControls.TextBox Ctl_SomeoneMobil;
		protected System.Web.UI.WebControls.Label Lb_SomeoneMobil;
		protected System.Web.UI.WebControls.Label lbIsSensitiveIssue;
		protected System.Web.UI.WebControls.Label lbKeyMessage;
		protected System.Web.UI.WebControls.RadioButtonList RBL_KeyMessage1;
		protected System.Web.UI.WebControls.DropDownList Dp_Account;
		protected System.Web.UI.HtmlControls.HtmlTableRow TR_Account;
		protected System.Web.UI.WebControls.Label lbContractSum;
		protected System.Web.UI.WebControls.Label lbCostSum;
		protected System.Web.UI.WebControls.Label lbEZVisitNoReadOnly;
		protected System.Web.UI.WebControls.Label lbLGDNoReadOnly;
		protected System.Web.UI.HtmlControls.HtmlTableRow TR_ID;
		protected System.Web.UI.WebControls.DropDownList ddlLegalEntity;
		protected System.Web.UI.WebControls.Label lblLegalEntity;
		protected System.Web.UI.WebControls.Label lbSummaryReadOnly;
		protected System.Web.UI.HtmlControls.HtmlTableRow TR_KnowledgeTitle;
		protected System.Web.UI.HtmlControls.HtmlTableRow TR_Knowledge;
//		protected System.Web.UI.WebControls.TextBox Ctl_LogisticComment;
		protected System.Web.UI.WebControls.Label lbLogisticComment;
		protected System.Web.UI.WebControls.DropDownList Dp_ExpenseType;
		private bool _isKnowledgeVisible = false;
		protected System.Web.UI.WebControls.Label lbExpenseTypeReadOnly;
		private bool _isReadOnly = false;
		protected System.Web.UI.WebControls.RadioButtonList rbHotelRequired;

		protected System.Web.UI.WebControls.TextBox tbPriceRangeFrom;
		protected System.Web.UI.WebControls.TextBox tbPriceRangeTo;
		protected System.Web.UI.WebControls.RadioButtonList rbTransportationRequired;
		protected System.Web.UI.WebControls.RadioButtonList rbInterpreterRequired;
		protected System.Web.UI.WebControls.RadioButtonList rbSimultaneousConsecutive;
		protected System.Web.UI.WebControls.RadioButtonList rbSpecialDialect;
		protected System.Web.UI.WebControls.TextBox tbTravel;
		protected System.Web.UI.WebControls.TextBox tbHotelPreferences;

		protected System.Web.UI.WebControls.Label lbHotelRequiredReadOnly;
		protected System.Web.UI.WebControls.Label lbHotelPreferencesReadOnly;
		protected System.Web.UI.WebControls.Label lbPriceRangeFromReadOnly;
		protected System.Web.UI.WebControls.Label lbPriceRangeToReadOnly;
		protected System.Web.UI.WebControls.Label lbTransportationRequiredReadOnly;
		protected System.Web.UI.WebControls.Label lbInterpreferRequiredReadOnly;
		protected System.Web.UI.WebControls.Label lbSimultaneousConsecutiveReadOnly;
		//protected System.Web.UI.WebControls.Label lbSpecialDialectReadOnly;
		protected System.Web.UI.WebControls.Label lbTravelReadOnly;
		protected System.Web.UI.WebControls.TextBox tbReceivedGift;
		protected System.Web.UI.WebControls.DropDownList ddlPayingFor;
		protected System.Web.UI.WebControls.Label lbPayingForReadOnly;
		protected System.Web.UI.WebControls.RadioButtonList rbDirectToProvider;
		protected System.Web.UI.WebControls.Label lbDirectToProviderReadOnly;
		protected System.Web.UI.HtmlControls.HtmlGenericControl img6;
		protected System.Web.UI.HtmlControls.HtmlGenericControl span6;
		protected System.Web.UI.HtmlControls.HtmlGenericControl img7;
		protected System.Web.UI.HtmlControls.HtmlGenericControl span7;
		protected System.Web.UI.HtmlControls.HtmlGenericControl span8;
		protected System.Web.UI.HtmlControls.HtmlGenericControl span10;
		protected System.Web.UI.HtmlControls.HtmlGenericControl span12;
		protected System.Web.UI.HtmlControls.HtmlGenericControl span14;
		protected System.Web.UI.HtmlControls.HtmlGenericControl span15;
		protected System.Web.UI.HtmlControls.HtmlGenericControl img4;
		protected System.Web.UI.HtmlControls.HtmlGenericControl img5;
		protected System.Web.UI.WebControls.Label lbSpecialDialectReadOnly;
		protected System.Web.UI.WebControls.Label lbReceivedGiftDescriptionReadOnly; 
		#endregion

		#region Properties
		public bool KnowledgeVisible
		{
			set
			{
				_isKnowledgeVisible = value;
			}
			get
			{
				return _isKnowledgeVisible;
			}
		}
		public string RequestDateFrom
		{
			get
			{
				return this.tbRequestedDateFrom.Text;
			}
		}
		public string RequestDateTo
		{
			get
			{
				return this.tbRequestedDateTo.Text;
			}
		}
		protected DateTime RequestDate
		{
			get
			{ 
				if( this.ViewState["RequestDate"] == null )
					return System.DateTime.Now;
				return (DateTime)this.ViewState["RequestDate"]; 
			}
			set{ this.ViewState["RequestDate"] = value; }
		}
		public bool isReadOnly
		{
			set
			{
				_isReadOnly = value;
			}
			get
			{
				return _isReadOnly;
			}
		}
		public bool isNeedGift
		{
			get
			{
				return this.rbGiftNeed.SelectedValue == "1";
			}
		}
		public bool isNeedContract
		{
			get
			{
				return this.rbSalesContract.SelectedValue == "1";
			}
		}
		public int CustomerID
		{
			set
			{
				ViewState["customerID"] = value;
			}
			get
			{
				if(ViewState["customerID"] == null)
					return 0;
				return Convert.ToInt32(ViewState["customerID"]);
			}
		}
		public int BusinessID
		{
			set
			{
				ViewState["businessID"] = value;
			}
			get
			{
				if(ViewState["businessID"] == null)
					return 0;
				return Convert.ToInt32(ViewState["businessID"]);
			}
		}
		public int TopicID
		{
			set
			{
				ViewState["topicID"] = value;
			}
			get
			{
				if(ViewState["topicID"] == null)
					return 0;
				return Convert.ToInt32(ViewState["topicID"]);
			}
		}
		public int SalesTeamID
		{
			set
			{
				ViewState["salesTeamID"] = value;
			}
			get
			{
				if(ViewState["salesTeamID"] == null)
					return 0;
				return Convert.ToInt32(ViewState["salesTeamID"]);
			}
		}
		public int LogistID
		{
			set
			{
				ViewState["logistID"] = value;
			}
			get
			{
				if(ViewState["logistID"] == null)
					return 0;
				return Convert.ToInt32(ViewState["logistID"]);
			}
		}
		public int PaymentID
		{
			set
			{
				ViewState["paymentID"] = value;
			}
			get
			{
				if(ViewState["paymentID"] == null)
					return 0;
				return Convert.ToInt32(ViewState["paymentID"]);
			}
		}

		public string Dp_Dept_Value
		{
			get
			{
				return this.Dp_Department.SelectedItem.Value.ToString();
			}
		}
		public string Dp_CAT_Value
		{
			get
			{
				return this.Dp_Account.SelectedItem.Value.ToString();
			}
		}
		protected string ApplicationNo
		{
			get
			{ 
				if( this.ViewState["ApplicationNo"] == null )
					return string.Empty;
				return this.ViewState["ApplicationNo"].ToString(); 
			}
			set{ this.ViewState["ApplicationNo"] = value; }
		}
		private bool IsView
		{
			get
			{
				string state = this.Request.QueryString["State"];
				if(state == null) return false;
				if(state == SysDicItem.ProjectStatusFlag.QUERY || state == SysDicItem.ProjectStatusFlag.View
					|| state == SysDicItem.ProjectStatusFlag.Pending || state == SysDicItem.ProjectStatusFlag.End)
					return true;
				else
					return false;
			}
		}
		protected string Step
		{
			get
			{
				IQuery queryService = BEGDC.Utility.Castle.AppContainer.Instance[BEGDC.CC.BL.Common.ServiceConst.QueryService] as IQuery;
				FlowInstance flowInstance = queryService.QueryFlowInstance( this.AppID );
				if( flowInstance == null )
					return "Close";
				else
					return flowInstance.CurrentActiveStep.StepCode;
			}
		}

		public int CustomerNum
		{
			get
			{
				if(this.dgCustomerList!=null)
					return this.dgCustomerList.Items.Count;
				else
					return 0;
			}
		}

		public int AccompanyNum
		{
			get
			{
				if(this.dgALAttendee!=null)
					return this.dgALAttendee.Items.Count;
				else
					return 0;
			}
		}

		public int HotelNum
		{
			get
			{

					return 0;
			}
		}

		public int CostCenterNum
		{
			get
			{
				if(this.dgCostCenter!=null)
					return this.dgCostCenter.Items.Count;
				else
					return 0;
			}
		}

		public bool IsSomeoneElse
		{
			get
			{
				if(this.rbSomeoneElse.SelectedValue=="1")
				{
					return true;
				}
				else
				{
					return false;
				}
			}
		}

		public BEGDC.CC.Entity.Employee SomeoneEmployee
		{
			get
			{
				if(this.SearchStaff.EmployeeID!="")
				{
					return this.GetUserById(this.SearchStaff.EmployeeID);
				}
				else
				{
					return null;
				}
			}
		}
		#endregion

		private void Page_Load(object sender, System.EventArgs e)
		{


			// Put user code to initialize the page here
			if(!Page.IsPostBack)
			{
				this.TR_Knowledge.Visible = false;
				this.TR_KnowledgeTitle.Visible  =false;

				//base.PreInitForm();
				InitialDropDownList();
				BindApplication();

				//this.SearchStaff.SelfID = ((BEGDC.CC.BL.Workflow.CCIdentity)Page.User.Identity).UserInfo.Id;
				
				#region Radio List OnClick
				this.rbSomeoneElse.Attributes["onclick"] = "javascript:ShowSomeOneElsePane();";
				this.rbOutStandingRFP.Attributes["onclick"] = "javascript:ShowRFPDetailPane();";
				this.RB_IsSensitiveIssue.Attributes["onclick"] = "javascript:ShowSensitiveIssuePane();";
				this.RBL_KeyMessage.Attributes["onclick"] = "javascript:ShowKeyMessageDetailPane();";

				this.rbSalesContract.Attributes["onclick"] = "javascript:ShowSalesContractPane();";
				this.rbSalesContractSigned.Attributes["onclick"] = "javascript:ShowSalesContractSignedPane();";
				this.rbActivityInTrip.Attributes["onclick"] = "javascript:ShowActivityInTripPane();";

				//this.RBL_Meal.Attributes["onclick"] = "javascript:ShowRBL_MealPane();";
				//this.rbEntertainmentNeed.Attributes["onclick"] = "javascript:ShowEntertainmentNeedPane();";
				//this.rbGiftNeed.Attributes["onclick"] = "javascript:ShowGiftNeedPane();";
				//this.rbReceivedGift.Attributes["onclick"] = "javascript:ShowReceivedGiftPane();";

				#endregion

				//RegisterClientScripts();
				
			}
			else
			{
				#region RELOAD DATAGRID
				BindCustomerAttendee();
				BindALAttendee();
				BindCostCenter();
				BindContractInfo();
				#endregion
			}
//			Page.SmartNavigation = true;
			ShowBlock();

		}

		#region RegisterClientScripts
//		public void RegisterClientScripts()
//		{
//			StringBuilder sb = new StringBuilder();
//			if(Page.IsPostBack)
//			{
//				//Post back get init value from control.
//				sb.Append("<script language=\"javascript\">\n");
//				sb.Append("var _SomeoneElse;\n");
//				sb.Append("var _RFPDetail;\n");
//				sb.Append("var _SensitiveIssue;\n");
//				sb.Append("var _KeyMessageDetail;\n");
//				sb.Append("var _SalesContract;\n");
//				sb.Append("var _SalesContractSigned;\n");
//				sb.Append("var _ActivityInTrip;\n");
//				sb.Append("var _EntertainmentNeed;\n");
//				sb.Append("var _GiftNeed;\n");
//				sb.Append("var _ReceivedGift;\n");
//				sb.Append("var _TravelAgency;\n");
//				if(this.Application == null)
//				{
//					sb.Append("_SomeoneElse = false;\n");
//				}
//				else
//				{
//					sb.Append("_SomeoneElse = ");
//					sb.Append(this.Application.ApplyForSomeoneElse ? "true":"false");
//					sb.Append(";\n");
//				}
//
//				sb.Append("_RFPDetail = ");
//				sb.Append(this.rbOutStandingRFP.SelectedValue == "1" ? "true":"false");
//				sb.Append(";\n");
//				sb.Append("_SensitiveIssue = ");
//				sb.Append(this.RB_IsSensitiveIssue.SelectedValue == "1" ? "true":"false");
//				sb.Append(";\n");
//				sb.Append("_KeyMessageDetail = ");
//				sb.Append(this.RBL_KeyMessage.SelectedValue =="1" ? "true":"false");
//				sb.Append(";\n");
//				sb.Append("_SalesContract = ");
//				sb.Append(this.rbSalesContract.SelectedValue == "1" ? "true":"false");
//				sb.Append(";\n");
//				sb.Append("_SalesContractSigned = ");
//				sb.Append(this.rbSalesContractSigned.SelectedValue =="1" ? "true":"false");
//				sb.Append(";\n");
//				sb.Append("_ActivityInTrip = ");
//				sb.Append(this.rbActivityInTrip.SelectedValue =="1" ? "true":"false");
//				sb.Append(";\n");
//				sb.Append("_EntertainmentNeed = ");
//				sb.Append(this.rbEntertainmentNeed.SelectedValue =="1" ? "true":"false");
//				sb.Append(";\n");
//				sb.Append("_GiftNeed = ");
//				sb.Append(this.rbGiftNeed.SelectedValue=="1" ? "true":"false");
//				sb.Append(";\n");
//				sb.Append("_ReceivedGift = ");
//				sb.Append(this.rbReceivedGift.SelectedValue=="1" ? "true":"false");
//				sb.Append(";\n");
//				sb.Append("_TravelAgency = ");
//				sb.Append(this.RB_IsTravelAgency.SelectedValue == "1" ? "true":"false");
//				sb.Append(";\n");
//				sb.Append("</script>");
//			}
//			else
//			{
//				sb.Append("<script language=\"javascript\">\n");
//				sb.Append("var _SomeoneElse;\n");
//				sb.Append("var _RFPDetail;\n");
//				sb.Append("var _SensitiveIssue;\n");
//				sb.Append("var _KeyMessageDetail;\n");
//				sb.Append("var _SalesContract;\n");
//				sb.Append("var _SalesContractSigned;\n");
//				sb.Append("var _ActivityInTrip;\n");
//				sb.Append("var _EntertainmentNeed;\n");
//				sb.Append("var _GiftNeed;\n");
//				sb.Append("var _ReceivedGift;\n");
//				sb.Append("var _TravelAgency;\n");
//				if(this.Application == null) 
//				{
//					sb.Append("_SomeoneElse = false;\n");
//				}
//				else
//				{
//					sb.Append("_SomeoneElse = ");
//					sb.Append(this.Application.ApplyForSomeoneElse ? "true":"false");
//					sb.Append(";\n");
//				}
//
//				sb.Append("_RFPDetail = ");
//				sb.Append(m_CachedCustomer==null? "false":(m_CachedCustomer.IsInRFP ? "true":"false"));
//				sb.Append(";\n");
//				sb.Append("_SensitiveIssue = ");
//				sb.Append(m_CachedCustomer==null? "false":(m_CachedCustomer.IsSensitiveIssue ? "true":"false"));
//				sb.Append(";\n");
//				sb.Append("_KeyMessageDetail = ");
//				sb.Append(m_CachedCustomer==null? "false":(m_CachedCustomer.IsKeyMessage ? "true":"false"));
//				sb.Append(";\n");
//				sb.Append("_SalesContract = ");
//				sb.Append(m_CachedBusiness==null? "false":(m_CachedBusiness.IsInSalesContract ? "true":"false"));
//				sb.Append(";\n");
//				sb.Append("_SalesContractSigned = ");
//				sb.Append(m_CachedBusiness==null? "false":(m_CachedBusiness.IsContractSigned ? "true":"false"));
//				sb.Append(";\n");
//				sb.Append("_ActivityInTrip = ");
//				sb.Append(m_CachedBusiness==null? "false":(m_CachedBusiness.RecreationalActivity ? "true":"false"));
//				sb.Append(";\n");
//				sb.Append("_EntertainmentNeed = ");
//				sb.Append(m_CachedLogist==null? "false":(m_CachedLogist.IsNeedEntertainment ? "true":"false"));
//				sb.Append(";\n");
//				sb.Append("_GiftNeed = ");
//				sb.Append(m_CachedLogist==null? "false":(m_CachedLogist.IsNeedGift ? "true":"false"));
//				sb.Append(";\n");
//				sb.Append("_ReceivedGift = ");
//				sb.Append(m_CachedLogist==null? "false":(m_CachedLogist.IsReceivedALGiftBefore ? "true":"false"));
//				sb.Append(";\n");
//				sb.Append("_TravelAgency = ");
//				sb.Append(m_CachedLogist==null? "false":(m_CachedLogist.IsNeedTravelAgency ? "true":"false"));
//				sb.Append(";\n");
//				sb.Append("</script>");
//				
//			}
//
//			if(!Page.IsClientScriptBlockRegistered("EZCtrlForCO"))
//			{
//				Page.RegisterClientScriptBlock("EZCtrlForCO",sb.ToString());
//			}
//			sb = new StringBuilder();
//			if(!Page.IsStartupScriptRegistered("EZCtrlForCO_Startup"))
//			{
//				sb.Append( "<script language=\"javascript\">\n");
//				sb.Append( "DisplaySomeOneElsePane(_SomeoneElse);\n");
//				sb.Append( "DisplayRFPDetailPane(_RFPDetail);\n");
//				sb.Append( "DisplaySensitiveIssuePane(_SensitiveIssue);\n");
//				sb.Append( "DisplayKeyMessageDetailPane(_KeyMessageDetail);\n");
//				sb.Append( "DisplaySalesContractPane(_SalesContract);\n");
//				sb.Append( "DisplaySalesContractSignedPane(_SalesContractSigned);\n");
//				sb.Append( "DisplayActivityInTripPane(_ActivityInTrip);\n");
//				//sb.Append( "DisplayRBL_MealPane(_RBL_Meal);\n");
//				sb.Append( "DisplayEntertainmentNeedPane(_EntertainmentNeed);\n");
//				sb.Append( "DisplayGiftNeedPane(_GiftNeed);\n");
//				sb.Append( "DisplayReceivedGiftPane(_ReceivedGift);\n");
//				sb.Append( "DisplayTravelAgencyPane(_TravelAgency);\n");
//				sb.Append("</script>\n");
//
//				Page.RegisterStartupScript("EZCtrlForCO_Startup",sb.ToString());
//			}
//		}
		#endregion

		#region ShowBlock
		private void ShowBlock()
		{
			StringBuilder sb = new StringBuilder();
			if(!Page.IsStartupScriptRegistered("EZCtrlForCO_Startup"))
			{
				sb.Append( "<script language=\"javascript\">\n");
				if(this.isReadOnly)
				{
					sb.Append( "DisplaySomeOneElsePane("+this.rbSomeoneElse.SelectedValue+");\n");
					sb.Append( "DisplayRFPDetailPane("+this.rbOutStandingRFP.SelectedValue+");\n");
					sb.Append( "DisplaySensitiveIssuePane("+this.RB_IsSensitiveIssue.SelectedValue+");\n");
					sb.Append( "DisplayKeyMessageDetailPane("+this.RBL_KeyMessage.SelectedValue+");\n");
					
					sb.Append("_showHotelPart("+this.rbHotelRequired.SelectedValue+");\n");
					sb.Append("_ShowGiftPart("+this.rbGiftNeed.SelectedValue+");\n");
					sb.Append("_ShowReceivedGiftPart("+this.rbReceivedGift.SelectedValue+");\n");
					sb.Append("_ShowEnterment("+this.rbEntertainmentNeed.SelectedValue+");\n");
					sb.Append("_ShowInterpreterPart("+this.rbInterpreterRequired.SelectedValue+");");

					sb.Append( "DisplayActivityInTripPane("+this.rbActivityInTrip.SelectedValue+");\n");
					sb.Append( "DisplaySalesContractPane("+this.rbSalesContract.SelectedValue+");\n");
					sb.Append( "DisplaySalesContractSignedPane("+this.rbSalesContractSigned.SelectedValue+");\n");
				}
				else
				{
					sb.Append( "ShowSomeOneElsePane();\n");
					sb.Append( "ShowRFPDetailPane();\n");
					sb.Append( "ShowSensitiveIssuePane();\n");
					sb.Append( "ShowKeyMessageDetailPane();\n");

					sb.Append("showHotelPart();\n");
					sb.Append("ShowGiftPart();\n");
					sb.Append("ShowReceivedGiftPart();\n");
					sb.Append("ShowEnterment();\n");
					sb.Append("ShowInterpreterPart();\n");

					sb.Append( "ShowActivityInTripPane();\n");
					sb.Append( "ShowSalesContractPane();\n");
				}
				//sb.Append( "ShowSalesContractSignedPane();\n");
				sb.Append("</script>\n");

				Page.RegisterStartupScript("EZCtrlForCO_Startup",sb.ToString());
			}
		}
		#endregion

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		///		Required method for Designer support - do not modify
		///		the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.Dp_Department.SelectedIndexChanged += new System.EventHandler(this.CATBranch_SelectChange);
			this.rbSomeoneElse.SelectedIndexChanged += new System.EventHandler(this.rbSomeoneElse_SelectedIndexChanged);
			this.rbSalesContractSigned.SelectedIndexChanged += new System.EventHandler(this.Contract_Select);
			this.dgContractInfo.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgContractInfo_DeleteCommand);
			this.dgContractInfo.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgContractInfo_ItemDataBound);
			this.dgCustomerList.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgCustomerList_DeleteCommand);
			this.dgCustomerList.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgCustomerList_ItemDataBound);
			this.dgALAttendee.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgALAttendee_DeleteCommand);
			this.dgALAttendee.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgALAttendee_ItemDataBound);
			this.dgCostCenter.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgCostCenter_DeleteCommand);
			this.dgCostCenter.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgCostCenter_ItemDataBound);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		#region InitialDropDownList
		private void InitialDropDownList()
		{
			IQuery queryService = BEGDC.Utility.Castle.AppContainer.Instance[BEGDC.CC.BL.Common.ServiceConst.QueryService] as IQuery;

			WebUtility.BuildDropDown(ddlPotentialRevenueTime,BEGDC.CC.BL.Common.DicType.POTENTIAL_REVENUE_TIMEFRAME,false,false);
			WebUtility.BuildDropDown(ddlSaleStage,BEGDC.CC.BL.Common.DicType.SALES_STAGE,false,false);
			WebUtility.BuildDropDown(ddlAccountType,BEGDC.CC.BL.Common.DicType.ACCOUNT_TYPE,false,false);
			WebUtility.BuildDropDown(ddlSalesBusinessUnit,BEGDC.CC.BL.Common.DicType.SALES_BUSINESS_UNIT,false,false);
			WebUtility.BuildDropDown(ddlRegion,BEGDC.CC.BL.Common.DicType.REGION,false,false);
			WebUtility.BuildDropDown(ddlPayingFor,BEGDC.CC.BL.Common.DicType.PAYER,false,false);

			//WebUtility.BuildDropDown(ddlPayingFor,BEGDC.CC.BL.Common.DicType.PAYER,false,false);
			//WebUtility.BuildCheckBoxList(cblPreferredLocation,BEGDC.CC.BL.Common.DicType.VISITING_SITES);
			//WebUtility.BuildCheckBoxList(this.cblDomesticOversea,BEGDC.CC.BL.Common.DicType.Domestic);

			BEGDC.CC.BL.Common.IUtility utility = AppContainer.Instance[ServiceConst.UtilityService] as BEGDC.CC.BL.Common.IUtility;
			IList DeptList = utility.BuildDicList(BEGDC.CC.BL.Common.DicType.BRANCH);

			this.ddlLegalEntity.DataSource = queryService.GetAllLegalEntity();
			this.ddlLegalEntity.DataTextField = "LegalEntityName";
			this.ddlLegalEntity.DataValueField = "LegalEntityID";
			this.ddlLegalEntity.DataBind();

			//			this.ddlCATBranch.DataSource = DeptList;
			//			this.ddlCATBranch.DataValueField = "DicItemKey";
			//			this.ddlCATBranch.DataTextField = "Description";
			//			this.ddlCATBranch.DataBind();
			//
			//			this.ddlCATBranch.Items.Insert(0,new System.Web.UI.WebControls.ListItem("其他部门","OTH"));
			//			this.ddlCATBranch.Items.Insert(0,new System.Web.UI.WebControls.ListItem("总公司","HQ"));
			//			
			//			IList CATList = utility.GetALLCATList();
			//			this.ddlAccount.DataSource = CATList;
			//			this.ddlAccount.DataValueField = "DepartmentCode";
			//			this.ddlAccount.DataTextField = "DepartmentCode";
			//			this.ddlAccount.DataBind();
		}
		#endregion

		#region BindApplication

		private void BuildDepartmentCATList()
		{
			//BEGDC.CC.BL.Common.IUtility utility = AppContainer.Instance[ServiceConst.UtilityService] as BEGDC.CC.BL.Common.IUtility;
			//IList DeptList = utility.BuildDicList(BEGDC.CC.BL.Common.DicType.BRANCH);

			BEGDC.CC.BL.Common.Query.IQuery queryService = AppContainer.Instance[ServiceConst.QueryService] as BEGDC.CC.BL.Common.Query.IQuery;
			DataTable catTable = queryService.GetDeptByTypeName( BEGDC.CC.BL.Common.DicType.CAT );
			DataTable branchTable = queryService.GetDeptByTypeName( BEGDC.CC.BL.Common.DicType.BRANCH );

			DataRow[] rows = catTable.Select();
			foreach( DataRow row in rows )
			{
				branchTable.ImportRow(row);
			}

			this.Dp_Department.DataSource = branchTable;
			this.Dp_Department.DataValueField = "DepartmentCode";
			this.Dp_Department.DataTextField = "DepartmentCode";
			this.Dp_Department.DataBind();

			this.Dp_Department.Items.Insert(this.Dp_Department.Items.Count,new System.Web.UI.WebControls.ListItem("Other Department","OTH"));
			//this.Dp_Department.Items.Insert(0,new System.Web.UI.WebControls.ListItem("HQ","HQ"));

			if(this.Dp_Department.Items.Count>0)
			{
				this.Dp_Department.Items[0].Selected = true;
			}

			// Initialize Account Dropdown List

			DataTable accountTable = queryService.GetDicItemByTypeName( BEGDC.CC.BL.Common.DicType.ACCOUNT );
			this.Dp_Account.DataSource = accountTable.DefaultView;
			this.Dp_Account.DataValueField = "DicItemKey";
			this.Dp_Account.DataTextField = "DicItemKey";
			this.Dp_Account.DataBind();

			//			this.Dp_CAT.DataSource = catTable;
			//			this.Dp_CAT.DataValueField = "DepartmentCode";
			//			this.Dp_CAT.DataTextField = "DepartmentCode";
			//			this.Dp_CAT.DataBind();
			if(this.Dp_Account.Items.Count>0)
			{
				this.Dp_Account.Items[0].Selected = true;
			}
		}

		private void BindApplication()
		{
			this.LoadApplication();

			if(this.Application!=null)
			{
				if(!this.Application.IsTransition) return;
			}

			if(this.Application!=null && this.Application.AppNo != string.Empty)
				this.lbAppNo.Text = "("+this.Application.AppNo+")";

			BuildDepartmentCATList();

			if(this.Application!=null)
			{
				if(this.Application.EZVisitReqNo!=""||this.Application.LGDNo!="")
				{
					this.lbEZVisitNoReadOnly.Text = this.Application.EZVisitReqNo;
					this.lbLGDNoReadOnly.Text = this.Application.LGDNo;
					this.TR_ID.Visible = true;
				}
				else
				{
					this.TR_ID.Visible = false;
				}
				this.Dp_Department.SelectedIndex = Dp_Department.Items.IndexOf(Dp_Department.Items.FindByValue(this.Application.AllDept));
				//this.Dp_Account.SelectedIndex = this.Dp_Account.Items.IndexOf(this.Dp_Account.Items.FindByText(this.Application.Account));
				if(this.Application.Account!=string.Empty)
				{
					this.Dp_Account.SelectedIndex = this.Dp_Account.Items.IndexOf(this.Dp_Account.Items.FindByText(this.Application.Account));
				}
				else
				{
					this.TR_Account.Visible = false;
				}
			}
			else
			{
				this.TR_ID.Visible = false;
			}

			Employee CurrentUser = this.GetUser(HttpContext.Current.User.Identity.Name);

			if(this.AppID == 0)
			{
				BindHotelData(null);
				BindLeaseCarData(null);
				BindContractInfo();
				BindCustomerAttendee();
				BindALAttendee();
				BindCostCenter();
				if(CurrentUser!=null)
				{
					this.tbRequestorName.Text = CurrentUser.NameEN;
					//Employee emp = this.GetUser(HttpContext.Current.User.Identity.Name);
					this.lbDepartmentReadOnly.Text = CurrentUser.Department.DepartmentCode;
				}
				return;
			}

			IQuery queryService = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
			CustomerInfo customer = queryService.GetCustomerInfo(this.AppID);
			BusinessPurpose business = queryService.GetBusinessPurposeInfo(this.AppID);
			Topic topic = queryService.GetTopicInfo(this.AppID);
			SalesTeamInfo salesTeam = queryService.GetSalesTeamInfo(this.AppID);
			LogisticalInfo logist = queryService.GetLogisticalInfo(this.AppID);
			PaymentInfo payment = queryService.GetPaymentInfo(this.AppID);
			//DataTable visitingSite = queryService.GetVisitingSite(this.AppID);

			this.CustomerID = customer.Id;
			this.BusinessID = business.Id;
			this.TopicID = topic.Id;
			this.SalesTeamID = salesTeam.Id;
			this.LogistID = logist.Id;
			this.PaymentID = payment.Id;

			BindApplicationData();
			BindCustomerInfoData(customer);
			BindBusinessPurposeData(business);
			BindTopicData(topic);
			BindSalesTeamData(salesTeam);
			BindLogisticalData(logist);

			BindPaymentData(payment);
			BindCustomerAttendee();
			BindALAttendee();
			BindCostCenter();
			BindContractInfo();

			if(this.isReadOnly)
				BindReadOnlyStatus();
		}

		private Employee GetUser(string name)
		{
			IUser userService = AppContainer.Instance[ServiceConst.UserService] as IUser;
			return userService.GetUser(name);
		}

		private Employee GetUserById(string Id)
		{
			IUser userService = AppContainer.Instance[ServiceConst.UserService] as IUser;
			return userService.GetUserByID(Id);
		}

		private void BindApplicationData()
		{
			this.tbRequestorName.Text = this.Application.RequesterNameEN;
			this.tbRequestOfficeTel.Text = this.Application.RequesterOfficeTel;
			this.tbRequestorMobile.Text = this.Application.RequesterMobile;
			this.rbReviewGuideLine.SelectedValue = this.Application.IsReviewedGuideline? "1":"0";
			this.tbOtherLocation.Text = this.Application.OtherSite;
			//this.tbOtherCountry.Text = this.Application.OtherCountry;

			if(this.Application.RequestedDateFrom!=null)
			{
				this.tbRequestedDateFrom.Text = ((DateTime)this.Application.RequestedDateFrom).ToString("MM/dd/yyyy");
			}
			if(this.Application.RequestedDateTo!=null)
			{
				this.tbRequestedDateTo.Text = ((DateTime)this.Application.RequestedDateTo).ToString("MM/dd/yyyy");
			}
			if(this.Application.AlternateDateFrom != null)
				this.tbAlternateDateFrom.Text = ((DateTime)this.Application.AlternateDateFrom).ToString("MM/dd/yyyy");
			if(this.Application.AlternateDateTo != null)
				this.tbAlternateDateTo.Text = ((DateTime)this.Application.AlternateDateTo).ToString("MM/dd/yyyy");

			if( Application.LegalEntity != null )
			{
				this.ddlLegalEntity.SelectedValue = Application.LegalEntity.Id.ToString();
			}
			if(this.KnowledgeVisible)
			{
				this.TR_Knowledge.Visible = true;
				this.TR_KnowledgeTitle.Visible  =true;
				this.lbSummaryReadOnly.Text = this.Application.Summary;
			}

			if( this.Application.DepartmentName != null )
			{
				this.lbDepartmentReadOnly.Text = this.Application.DepartmentName.DepartmentCode;			
			}

			this.ApplicationNo = this.Application.AppNo;
			if(this.Application.RequestDate != null)
				this.RequestDate = (DateTime)this.Application.RequestDate;
			//			this.ddlAccount.SelectedValue = this.Application.Account;
			//			this.ddlCATBranch.SelectedValue = this.Application.AllDept;

			this.rbSomeoneElse.SelectedValue = this.Application.ApplyForSomeoneElse? "1":"0";
			if(this.Application.ApplyForSomeoneElse&&this.Application.SomeoneElseNo!=null)
			{
				this.Ctl_HRID.Text = this.Application.SomeoneElseHRID;
				this.SearchStaff.EmployeeID = this.Application.SomeoneElseNo.Id;
				this.SearchStaff.EmployeeName = this.Application.SomeoneElseNameEN;
				this.tbSomeoneTel.Text = this.Application.SomeoneElseTel;
				this.Ctl_SomeoneMobil.Text = this.Application.SomeoneElseMobil;
				this.tbSomeoneEmail.Text = this.Application.SomeoneElseEmail;
			}

			this.tbOtherLocation.Text = this.Application.OtherSite;

//			string[] temp;
//			if(this.Application.IsDomestic)
//			{
//				this.rbDomesticOversea.SelectedValue = DOMESTIC;
//				temp = this.Application.DomesticList.Split(',');
//			}
//			else
//			{
//				this.rbDomesticOversea.SelectedValue = OVERSEA;
//				temp = this.Application.OverseaList.Split(',');
//			}
//
//			if(temp != null && temp.Length > 0)
//			{
//				for(int i=0; i<temp.Length; i++)
//					for(int j=0; j<this.cblDomesticOversea.Items.Count; j++)
//					{
//						if(temp[i] == cblDomesticOversea.Items[j].Value)
//							cblDomesticOversea.Items[j].Selected = true;
//					}
//			}
				
		}

		private void BindCustomerInfoData(CustomerInfo customer)
		{
			if(customer != null)
			{
				this.tbCustomerName.Text = customer.Company;
				this.rbIsFCPA.SelectedValue = customer.IsFCPA? "1":"0";
				this.tbCustomerCountry.Text = customer.Country;
//				this.tbGuestNumber.Text = customer.NumberOfPerson; 
				this.tbVisitObjectives.Text = customer.VisitObjective;
				this.tbPotentialRevenue.Text = customer.DecryptedRevenuePotential.ToString();
				this.ddlPotentialRevenueTime.SelectedValue = customer.PotentialRevenueTimeframe.ToString();
				this.ddlSaleStage.SelectedValue = customer.SalesStage.ToString();

				this.rbOutStandingRFP.SelectedValue = customer.IsInRFP? "1":"0"; 
				this.Ctl_RFPDetails.Text = customer.RFPDetail;
				this.RB_IsSensitiveIssue.SelectedValue = customer.IsSensitiveIssue? "1":"0"; 
				this.tbSensitiveIssues.Text = customer.IsThereSensitiveIssue;
				this.RBL_KeyMessage.SelectedValue = customer.IsKeyMessage? "1":"0";
				this.tbKeyMessage.Text = customer.IsThereKeyMessage;

				this.tbCompanyProfile.Text = customer.CompanyProfile;
				this.ddlAccountType.SelectedValue = customer.AccountType.Id.ToString(); 
				this.tbProposalNo.Text = customer.ProposalNo;
			}
		}

		private void BindBusinessPurposeData(BusinessPurpose business)
		{
			if(business != null)
			{
				this.rbSalesContract.SelectedValue = business.IsInSalesContract? "1":"0";
				this.rbSalesContractSigned.SelectedValue = business.IsContractSigned? "1":"0"; 
				//				this.tbContractDate.Text = ((DateTime)business.DateOfContract).ToString("MM/dd/yyyy");
				//				this.tbContractNo.Text = business.ContractNo;
				//				this.tbContractProducts.Text = business.ProductsSold;
				//				this.tbContractTripPurpose.Text = business.VisitPurposeInContract;
				//				this.tbContractQuotas.Text = business.Quotas.ToString();
				//				this.tbUnitPrice.Text = business.UnitPrice.ToString();
				this.tbNotSalesContractDescription.Text = business.Opportunities;
				this.rbActivityInTrip.SelectedValue = business.RecreationalActivity? "1":"0";
				this.Ctl_DetailedItinerary.Text = business.Itinerary;
				//this.rbALInvitation.SelectedValue = business.IsNeedInvitationLetter? "1":"0";
				//				this.tbReservedBudget.Text = business.Budget.ToString();
			}
		}

		private void BindTopicData(Topic topic)
		{
			if(topic != null)
			{
				this.tbTopic.Text = topic.TopicName;
			}
		}

		private void BindSalesTeamData(SalesTeamInfo salesTeam)
		{
			if(salesTeam != null)
			{
				this.tbCustomerTeamHost.Text = salesTeam.HostNameEN;
				this.tbCustomerOfficeTel.Text = salesTeam.OfficeTel;
				this.tbCustomerFax.Text = salesTeam.OfficeFax;
				this.tbCustomerEmail.Text = salesTeam.Email;
				this.ddlSalesBusinessUnit.SelectedValue = salesTeam.SalesBusinessUnit;
				this.ddlRegion.SelectedValue = salesTeam.Region;
			}
		}

		private void BindLogisticalData(LogisticalInfo logist)
		{
			if(logist != null)
			{
				this.rbHotelRequired.SelectedValue = logist.IsNeedHotel? "1":"0";
				this.tbHotelPreferences.Text = logist.HotelPreferences;
				if(logist.DateRequiredFrom != null)
					this.tbDatesRequiredFrom.Text = ((DateTime)logist.DateRequiredFrom).ToString("MM/dd/yyyy");
				if(logist.DateRequiredTo != null)
					this.tbDatesRequiredTo.Text = ((DateTime)logist.DateRequiredTo).ToString("MM/dd/yyyy");
				this.tbPriceRangeFrom.Text = logist.DecryptedPriceFrom.ToString();
				this.tbPriceRangeTo.Text = logist.DecryptedPriceTo.ToString();
				this.rbTransportationRequired.SelectedValue = logist.IsNeedGroundTransportation? "1":"0";
				this.rbEntertainmentNeed.SelectedValue = logist.IsNeedEntertainment? "1":"0";
				this.tbPreferEntertainment.Text = logist.EntertainmentPreference;
				this.tbEntertainmentPriceRangeFrom.Text = logist.DecryptedEntertainmentPriceFrom.ToString();
				this.tbEntertainmentPriceRangeTo.Text = logist.DecryptedEntertainmentPriceTo.ToString();
				this.rbGiftNeed.SelectedValue = logist.IsNeedGift? "1":"0"; 
				this.tbPreferGift.Text = logist.GiftPreference;
				this.tbGiftPriceRangeFrom.Text = logist.DecryptedGiftPriceFrom.ToString();
				this.tbGiftPriceRangeTo.Text = logist.DecryptedGiftPriceTo.ToString();
				this.rbReceivedGift.SelectedValue = logist.IsReceivedALGiftBefore? "1":"0";
				this.rbInterpreterRequired.SelectedValue = logist.IsNeedInterpreter? "1":"0";
				this.rbSimultaneousConsecutive.SelectedValue = logist.InterpretionType.ToString();
				this.rbSpecialDialect.SelectedValue = logist.SpecialDialect;
				this.tbTravel.Text = logist.TravelAgency;
			}
		}

		private void BindHotelData(LogisticalInfo LogisticalInfo)
		{
		}

		private void BindLeaseCarData(LogisticalInfo LogisticalInfo)
		{

		}

		private void BindPaymentData(PaymentInfo payment)
		{
			if(payment != null)
			{
				try
				{
					this.ddlPayingFor.SelectedValue = payment.Payer.ToString();
				}
				catch(System.Exception e)
				{}
				this.rbDirectToProvider.SelectedValue = payment.IsPayServiceProvider? "1":"0";
				this.tbNotDirectReason.Text = payment.NotDirectPayReasons;
				this.tbEstimateTotalCost.Text = payment.DecryptedEstimatedCustomerTotalCost.ToString();
				this.tbEstimateCostPerPerson.Text = payment.DecryptedEstimateCustomerdIndividualCost.ToString();
				this.tbReason.Text = payment.CustomerPerdiem;
			}
		}

		private void BindContractInfo()
		{
			DataTable ContractInfo = null;
			if(Session[SessionFlag.ContractInfo] != null)
			{
				ContractInfo = (DataTable)Session[SessionFlag.ContractInfo];
			}
			else
			{
				if(this.AppID > 0)
				{
					IQuery queryService = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
					ContractInfo = SetRowID(queryService.QueryContractInfoByAppId(this.AppID));
				}
				if(ContractInfo == null || ContractInfo.Rows.Count == 0)
				{
					ContractInfo = new DataTable();
					ContractInfo.Columns.Add(new DataColumn("RowId", typeof(System.String)));
					ContractInfo.Columns.Add(new DataColumn("DateOfContract", typeof(System.DateTime)));
					ContractInfo.Columns.Add(new DataColumn("ContractNo", typeof(System.String)));
					ContractInfo.Columns.Add(new DataColumn("ProducstSold", typeof(System.String)));
					ContractInfo.Columns.Add(new DataColumn("VisitPurposeInContract", typeof(System.String)));
					ContractInfo.Columns.Add(new DataColumn("Quotas", typeof(System.Int32)));
					ContractInfo.Columns.Add(new DataColumn("UnitPrice", typeof(System.Decimal)));
					ContractInfo.Columns.Add(new DataColumn("Budget", typeof(System.Decimal)));
				}
				Session[SessionFlag.ContractInfo] = ContractInfo;
			}
			this.dgContractInfo.DataSource = this.SetRowID(ContractInfo);
			this.dgContractInfo.DataBind();

			this.lbContractSum.Text = CalculateSum();
		}

		private DataTable SetRowID(DataTable table)
		{
			if(table != null && table.Rows.Count >0)
				for(int i=1; i<=table.Rows.Count; i++)
				{
					table.Rows[i-1][0] = i.ToString();
				}
			return table;
		}
	    #endregion

		#region BindCustomerAttendee
		private void BindCustomerAttendee()
		{
			DataTable CustomerDataTable = null;
			object SessCustomerAttendee = Session[SessionFlag.CustomerSessionEZ];
			if(SessCustomerAttendee!=null)
			{
				CustomerDataTable = (DataTable)SessCustomerAttendee;
			}
			else
			{
				if(this.CustomerID > 0)
				{
					IQuery queryService = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
					CustomerDataTable = queryService.GetCustomerAttendeeList(this.CustomerID);
				}
				if(CustomerDataTable!=null&&CustomerDataTable.Rows.Count>0)
				{
					Session[SessionFlag.CustomerSessionEZ] = CustomerDataTable;
				}
				else
				{
					CustomerDataTable = new DataTable();
					CustomerDataTable.Columns.Add(new DataColumn("Id", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("Name", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("Company", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("Title", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("NameCN", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("CompanyEN", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("TitleEN", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("Responsibility", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("Affects", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("ResponsibilityID", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("AffectsID", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("Remark", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("IsExisted", typeof(System.String)));
					Session[SessionFlag.CustomerSessionEZ] = CustomerDataTable;
				}
			}
			this.dgCustomerList.DataSource = this.SetRowID(CustomerDataTable);
			this.dgCustomerList.DataBind();
			if(CheckCISCustomer())
			{
				this.Lb_CISWarning.Visible = true;
			}
			else
			{
				this.Lb_CISWarning.Visible = false;
			}
			if(CustomerDataTable!=null&&CustomerDataTable.Rows.Count>0)
			{
				this.lbGuestNumberReadOnly.Text = CustomerDataTable.Rows.Count.ToString();
			}
			else
			{
				this.lbGuestNumberReadOnly.Text = "0";
			}
		}
		#endregion

		#region BindALAttendee
		private void BindALAttendee()
		{
			DataTable AccompanyingAttendee = null;
			if(Session[SessionFlag.AccompanySessionEZ] != null)
			{
				AccompanyingAttendee = (DataTable)Session[SessionFlag.AccompanySessionEZ];
			}
			else
			{
				if(this.AppID > 0)
				{
					ICR crService = AppContainer.Instance[ServiceConst.CRService] as ICR;
					AccompanyingAttendee = crService.GetAccompanyingAttendeeList(this.AppID);
				}
				if(AccompanyingAttendee == null || AccompanyingAttendee.Rows.Count == 0)
				{
					AccompanyingAttendee = new DataTable();
					AccompanyingAttendee.Columns.Add(new DataColumn("Id", typeof(System.String)));
					AccompanyingAttendee.Columns.Add(new DataColumn("EmployeeId", typeof(System.String)));
					AccompanyingAttendee.Columns.Add(new DataColumn("Name", typeof(System.String)));
					AccompanyingAttendee.Columns.Add(new DataColumn("Title", typeof(System.String)));
				}
				Session[SessionFlag.AccompanySessionEZ] = AccompanyingAttendee;
			}
			this.dgALAttendee.DataSource = this.SetRowID(AccompanyingAttendee);
			this.dgALAttendee.DataBind();
		}
		#endregion

		#region BindCostCenter
		private void BindCostCenter()
		{
			DataTable CostCenter = null;
			if(Session[SessionFlag.CostCenter] != null)
			{
				CostCenter = (DataTable)Session[SessionFlag.CostCenter];
			}
			else
			{
				if(this.PaymentID > 0)
				{
					IQuery queryService = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
					CostCenter = queryService.GetCostCenter(this.PaymentID);
				}
				if(CostCenter == null || CostCenter.Rows.Count == 0)
				{
					CostCenter = new DataTable();
					CostCenter.Columns.Add(new DataColumn("Id", typeof(System.String)));
					CostCenter.Columns.Add(new DataColumn("CostCenterCode", typeof(System.String)));
					CostCenter.Columns.Add(new DataColumn("Cost", typeof(System.String)));
					CostCenter.Columns.Add(new DataColumn("ActualCost", typeof(System.String)));
					CostCenter.Columns.Add(new DataColumn("ActualTransferCost", typeof(System.String)));
				}
				Session[SessionFlag.CostCenter] = CostCenter;
			}
			this.dgCostCenter.DataSource = this.SetRowID(CostCenter);
			this.dgCostCenter.DataBind();

			this.lbCostSum.Text = this.CalculateCostSum();
		}
		#endregion

		#region BindReadOnlyStatus
		private void BindReadOnlyStatus()
		{
			this.ALPaneImg.Visible = false;
			this.CustomerPaneImg.Visible = false;
			this.CostCenterPaneImg.Visible = false;
			this.ConrtractInfoPane.Visible = false;
			// Application
			this.tbRequestorName.Visible = false;
			this.lbRequestorNameReadOnly.Text = this.tbRequestorName.Text;
			this.tbRequestOfficeTel.Visible = false;
			this.lbRequestOfficeTelReadOnly.Text = this.tbRequestOfficeTel.Text;
			this.tbRequestorMobile.Visible = false;
			this.lbRequestorMobileReadOnly.Text = this.tbRequestorMobile.Text;
			this.ddlLegalEntity.Visible = false;
			this.lblLegalEntity.Text = this.ddlLegalEntity.SelectedItem.Text;

			this.Dp_Department.Visible = false;
			if(this.Dp_Department.SelectedItem!=null)
			{
				this.tx_AllDepts.Text = this.Dp_Department.SelectedValue;
			}
			this.Dp_Account.Visible = false;
			if(this.Dp_Account.SelectedItem!=null)
			{
				this.tx_Account.Text = this.Dp_Account.SelectedValue;
			}

			this.Ctl_HRID.Visible = false;
			this.LB_HRID.Text = this.Ctl_HRID.Text;

			this.rbReviewGuideLine.Visible = false;
			this.lbReviewGuideLineReadOnly.Text = this.rbReviewGuideLine.SelectedItem.Text;
			this.tbOtherLocation.Visible = false;
			this.lbOtherLocationReadOnly.Text = this.tbOtherLocation.Text;
//			this.tbOtherCountry.Visible = false;
//			this.lbOtherCountryReadOnly.Text = this.tbOtherCountry.Text;
			this.tbRequestedDateFrom.Visible = false;
			this.lbRequestedDateFromReadOnly.Text = this.tbRequestedDateFrom.Text;
			this.tbRequestedDateTo.Visible = false;
			this.lbRequestedDateToReadOnly.Text = this.tbRequestedDateTo.Text;
			this.Ctl_SomeoneMobil.Visible = false;
			this.tbAlternateDateFrom.Visible = false;
			this.lbAlternateDateFromReadOnly.Text = this.tbAlternateDateFrom.Text;
			this.tbAlternateDateTo.Visible = false;
			this.lbAlternateDateToReadOnly.Text = this.tbAlternateDateTo.Text;
			this.Lb_SomeoneMobil.Text = this.Ctl_SomeoneMobil.Text;

			this.rbSomeoneElse.Visible = false;
			this.lbSomeoneElseReadOnly.Text = this.rbSomeoneElse.SelectedItem.Text;
			this.SearchStaff.Visible = false;
			this.lbSomeoneNameReadOnly.Text = this.SearchStaff.EmployeeName;
			this.tbSomeoneTel.Visible = false;
			this.lbSomeoneTelReadOnly.Text = this.tbSomeoneTel.Text;
			this.tbSomeoneEmail.Visible = false;
			this.lbSomeoneEmailReadOnly.Text = this.tbSomeoneEmail.Text;
//			this.cblPreferredLocation.Visible = false;
//			for(int i=0; i<this.cblPreferredLocation.Items.Count; i++)
//				if(cblPreferredLocation.Items[i].Selected)
//					this.lbPreferredLocationReadOnly.Text += cblPreferredLocation.Items[i].Text + ",";
//			string temp = this.lbPreferredLocationReadOnly.Text;
//			if(temp != string.Empty)
//				this.lbPreferredLocationReadOnly.Text = temp.Substring(0, temp.Length -1);
			//ContractDateImg.Visible = false;

			//			this.ddlCATBranch.Visible = false;
			//			this.lbCATBranchReadOnly.Text = this.ddlCATBranch.SelectedItem.Text;
			//			this.ddlAccount.Visible = false;
			//			this.lbAccountReadOnly.Text = this.ddlAccount.SelectedItem.Text;
//			this.cblDomesticOversea.Visible = false;
//			for(int i=0; i<this.cblDomesticOversea.Items.Count; i++)
//				if(cblDomesticOversea.Items[i].Selected)
//					this.lbDomesticReadonly.Text += cblDomesticOversea.Items[i].Text + ",";
			
			// Customer
			this.tbCustomerName.Visible = false;
			this.lbCustomerNameReadOnly.Text = this.tbCustomerName.Text;
			this.rbIsFCPA.Visible = false;
			this.lbIsFCPAReadOnly.Text = this.rbIsFCPA.SelectedItem.Text;
			this.tbCustomerCountry.Visible = false;
			this.lbCustomerCountryReadOnly.Text = this.tbCustomerCountry.Text;
//			this.tbGuestNumber.Visible = false;
//			this.lbGuestNumberReadOnly.Text = this.tbGuestNumber.Text;
			this.tbVisitObjectives.Visible = false;
			this.lbVisitObjectivesReadOnly.Text = this.tbVisitObjectives.Text;
			this.tbPotentialRevenue.Visible = false;
			this.lbPotentialRevenueReadOnly.Text = this.tbPotentialRevenue.Text;
			this.ddlPotentialRevenueTime.Visible = false;
			this.lbPotentialRevenueTimeReadOnly.Text = this.ddlPotentialRevenueTime.SelectedItem.Text;
			this.ddlSaleStage.Visible = false;
			this.lbSaleStageReadOnly.Text = this.ddlSaleStage.SelectedItem.Text;

			this.rbOutStandingRFP.Visible = false;
			this.lbOutStandingRFPReadOnly.Text = this.rbOutStandingRFP.SelectedItem.Text;
			//--
			this.Ctl_RFPDetails.Visible = false;
			this.Lb_RFPDetails.Text = this.Ctl_RFPDetails.Text;
			//--

			this.RB_IsSensitiveIssue.Visible = false;
			this.lbIsSensitiveIssue.Text = this.RB_IsSensitiveIssue.SelectedItem.Text;
			this.tbSensitiveIssues.Visible = false;
			this.lbSeneitiveIssuesReadOnly.Text = this.tbSensitiveIssues.Text;

			this.RBL_KeyMessage.Visible = false;
			this.lbKeyMessage.Text = this.RBL_KeyMessage.SelectedItem.Text;
			this.tbKeyMessage.Visible = false;
			this.lbKeyMessageReadOnly.Text = this.tbKeyMessage.Text;

//			this.Ctl_MealEachCost.Visible = false;
//			this.LB_MealEachCost.Text = this.Ctl_MealEachCost.Text;
//			this.Ctl_LogisticComment.Visible = false;
//			this.lbLogisticComment.Text = this.Ctl_LogisticComment.Text;


			this.tbCompanyProfile.Visible = false;
			this.lbCompanyProfileReadOnly.Text = this.tbCompanyProfile.Text;
			this.ddlAccountType.Visible = false;
			this.lbAccountTypeReadOnly.Text = this.ddlAccountType.SelectedItem.Text;
			this.tbProposalNo.Visible = false;
			this.lbProposalNoReadOnly.Text = this.tbProposalNo.Text;

			//			RequestedDateFromImg.Visible = false;
			//			tbRequestedDateToImg.Visible = false;
			//			tbAlternateDateFromImg.Visible = false;
			//			tbAlternateDateToImg.Visible =false;
			//			tbDatesRequiredFromImg.Visible = false;
			//			tbDatesRequiredToImg.Visible = false;
			tbRequestedDateToSpan.Visible = false;
			RequestedDateFromspan.Visible = false;
			//tbDatesRequiredFromSpan.Visible = false;
			//tbDatesRequiredToSpan.Visible = false;

			//HotelBookingImg.Visible = false;
			//CompanyCarImg.Visible = false;
			//LeaseCarImg.Visible = false;

			this.tbOtherLocation.Visible = false;
			this.lbOtherLocationReadOnly.Text = this.tbOtherLocation.Text;


			// Business Purpose
			this.rbSalesContract.Visible = false;
			this.lbSalesContractReadOnly.Text = this.rbSalesContract.SelectedItem.Text;
			this.rbSalesContractSigned.Visible = false;
			this.lbSalesContractSignedReadOnly.Text = this.rbSalesContractSigned.SelectedItem.Text;
			this.tbNotSalesContractDescription.Visible = false;
			this.lbNotSalesContractDescriptionReadOnly.Text = this.tbNotSalesContractDescription.Text;
			this.rbActivityInTrip.Visible = false;
			this.lbActivityInTripReadOnly.Text = this.rbActivityInTrip.SelectedItem.Text;

			this.Ctl_DetailedItinerary.Visible = false;
			this.Lb_DetailedItinerary.Text = this.Ctl_DetailedItinerary.Text;

			// Topic
			this.tbTopic.Visible = false;
			this.lbTopicReadOnly.Text = this.tbTopic.Text;

			// Sales Team
			this.tbCustomerTeamHost.Visible = false;
			this.lbCustomerTeamHostReadOnly.Text = this.tbCustomerTeamHost.Text;
			this.tbCustomerOfficeTel.Visible = false;
			this.lbCustomerOfficeTelReadOnly.Text = this.tbCustomerOfficeTel.Text;
			this.tbCustomerFax.Visible = false;
			this.lbCustomerFaxReadOnly.Text = this.tbCustomerFax.Text;
			this.tbCustomerEmail.Visible = false;
			this.lbCustomerEmailReadOnly.Text = this.tbCustomerEmail.Text;
			this.ddlSalesBusinessUnit.Visible = false;
			this.lbSalesBusinessUnitReadOnly.Text = this.ddlSalesBusinessUnit.SelectedItem.Text;
			this.ddlRegion.Visible = false;
			this.lbRegionReadOnly.Text = this.ddlRegion.SelectedItem.Text;


			// LogisticalInfo

			this.rbHotelRequired.Visible = false;
			this.lbHotelRequiredReadOnly.Text = this.rbHotelRequired.SelectedItem.Text;
			this.tbHotelPreferences.Visible = false;
			this.lbHotelPreferencesReadOnly.Text = this.tbHotelPreferences.Text;
			this.tbDatesRequiredFrom.Visible = false;
			this.lbDatesRequiredFromReadOnly.Text = this.tbDatesRequiredFrom.Text;
			this.tbDatesRequiredTo.Visible = false;
			this.lbDatesRequiredToReadOnly.Text = this.tbDatesRequiredTo.Text;
			this.tbPriceRangeFrom.Visible = false;
			this.lbPriceRangeFromReadOnly.Text = this.tbPriceRangeFrom.Text;
			this.tbPriceRangeTo.Visible = false;
			this.lbPriceRangeToReadOnly.Text = this.tbPriceRangeTo.Text;
			this.rbTransportationRequired.Visible = false;
			this.lbTransportationRequiredReadOnly.Text = this.rbTransportationRequired.SelectedItem.Text;
			this.rbEntertainmentNeed.Visible = false;
			this.lbEntertainmentNeedReadOnly.Text = this.rbEntertainmentNeed.SelectedItem.Text;
			this.tbPreferEntertainment.Visible = false;
			this.lbPreferEntertainmentReadOnly.Text = this.tbPreferEntertainment.Text;
			this.tbEntertainmentPriceRangeFrom.Visible = false;
			this.lbEntertainmentPriceRangeFromReadOnly.Text = this.tbEntertainmentPriceRangeFrom.Text;
			this.tbEntertainmentPriceRangeTo.Visible = false;
			this.lbEntertainmentPriceRangeToReadOnly.Text = this.tbEntertainmentPriceRangeTo.Text;
			this.rbGiftNeed.Visible = false;
			this.lbGiftNeedReadOnly.Text = this.rbGiftNeed.SelectedItem.Text;
			this.tbPreferGift.Visible = false;
			this.lbPreferGiftReadOnly.Text = this.tbPreferGift.Text;
			this.tbGiftPriceRangeFrom.Visible = false;
			this.lbGiftPriceRangeFromReadOnly.Text = this.tbGiftPriceRangeFrom.Text;
			this.tbGiftPriceRangeTo.Visible = false;
			this.lbGiftPriceRangeToReadOnly.Text = this.tbGiftPriceRangeTo.Text;
			this.rbReceivedGift.Visible = false;
			this.lbReceivedGiftReadOnly.Text = this.rbReceivedGift.SelectedItem.Text;
			this.rbInterpreterRequired.Visible = false;
			this.lbInterpreferRequiredReadOnly.Text = this.rbInterpreterRequired.SelectedItem.Text;
			this.rbSimultaneousConsecutive.Visible = false;
			this.lbSimultaneousConsecutiveReadOnly.Text = this.rbSimultaneousConsecutive.SelectedItem.Text;
			this.rbSpecialDialect.Visible = false;
			//this.lbSpecialDialectReadOnly.Text = this.rbSpecialDialect.SelectedItem.Text;
			this.tbTravel.Visible = false;
			this.lbTravelReadOnly.Text = this.tbTravel.Text;
			this.tbReceivedGift.Visible = false;
			this.lbReceivedGiftDescriptionReadOnly.Text = this.tbReceivedGift.Text;

			// Payment Info
			this.ddlPayingFor.Visible = false;
			this.lbPayingForReadOnly.Text = this.ddlPayingFor.SelectedItem.Text;
			this.rbDirectToProvider.Visible = false;
			this.lbDirectToProviderReadOnly.Text = this.rbDirectToProvider.SelectedItem.Text;
			this.tbNotDirectReason.Visible = false;
			this.lbNotDirectReasonReadOnly.Text = this.tbNotDirectReason.Text;
			this.tbEstimateTotalCost.Visible = false;
			this.lbEstimateTotalCostReadOnly.Text = this.tbEstimateTotalCost.Text;
			this.tbEstimateCostPerPerson.Visible = false;
			this.lbEstimateCostPerPersonReadOnly.Text = this.tbEstimateCostPerPerson.Text;
			this.tbReason.Visible = false;
			this.lbReasonReadOnly.Text = this.tbReason.Text;


//			this.tbReason.Visible = false;
//			this.lbReasonReadOnly.Text = this.tbReason.Text;

			//			this.td_left.Visible = false;
			//			this.td_right.Visible = false;
			//         this.tr_Title.Visible = false;
			//			this.tr_Button.Visible = false;
			this.dgContractInfo.Columns[8].Visible =false;
			this.dgCustomerList.Columns[6].Visible = false;
			this.dgALAttendee.Columns[3].Visible = false;

			//this.DG_CompanyCar.Columns[4].Visible = false;
			//this.DG_LeaseCar.Columns[4].Visible = false;
			this.dgCostCenter.Columns[3].Visible = false;
		
		}
		#endregion

		#region CaculateTotalPriceForLeaseCar
		private string CaculateTotalPriceForLeaseCar(DataTable dataTable)
		{
			ICR CRService = AppContainer.Instance[ServiceConst.CRService] as ICR;
			double Total = 0;
			int VID = 0;
			int Quat = 0;
			double UnitPrice = 0;
			BEGDC.CC.Entity.VehicleType vehicle = null;
			if(dataTable==null||dataTable.Rows.Count==0) return Total.ToString();
			for(int i=0;i<dataTable.Rows.Count;i++)
			{
				VID = Convert.ToInt32(dataTable.Rows[i]["VehicleTypeId"].ToString());
				vehicle = CRService.GetVehicleType(VID);
				UnitPrice = Convert.ToDouble(vehicle.Price);
				Quat = Convert.ToInt32(dataTable.Rows[i]["VehicleNumber"].ToString());
				Total += UnitPrice*Quat;
			}
			return Total.ToString();
		}
		#endregion

		#region BuildApplication
		public void BuildApplication(ref Application app, ref CustomerInfo customer, ref BusinessPurpose business, 
			ref Topic topic, ref SalesTeamInfo salesTeam, ref LogisticalInfo logist, ref PaymentInfo payment, 
			ref IList customerAttendee, ref IList alAttendee, ref IList site, ref IList cost, ref IList contract,ref DataTable HotelTable, ref DataTable LeaseCarTable)
		{
			//			app.Id = this.AppID;
			//app.AppNo = "Temp App";
			app.EZVisitReqNo = string.Empty;
			app.LGDNo = string.Empty;
			app.ApplicationType = WorkflowTypes.CR;
			app.RequesterOfficeTel = this.tbRequestOfficeTel.Text.Trim();
			app.RequesterMobile = this.tbRequestorMobile.Text.Trim();

			if(this.Dp_Department.SelectedItem!=null)
			{
				app.AllDept = this.Dp_Department.SelectedValue.ToString();
			}
			if(this.Dp_Account.SelectedItem!=null)
			{
				app.Account = this.Dp_Account.SelectedValue.ToString();
			}
			if(this.ddlLegalEntity.SelectedItem!=null)
			{
				app.LegalEntity = new LegalEntity();
				app.LegalEntity.Id = Convert.ToInt32(this.ddlLegalEntity.SelectedValue);
			}

			IQuery query = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
			BEGDC.CC.Entity.Department dept = query.GetDepartmentByCode(this.Dp_Department.SelectedValue.ToString());
			if((dept!=null && (dept.DepartmentType.DicItemKey == BEGDC.CC.BL.Common.SysDicItem.DepartmentType.CAT)) || (this.Dp_Department.SelectedValue.ToString() == "OTH"))
			{
				//app.AllDept  = "HQ"+this.Dp_Department.SelectedValue.ToString();
				app.Account = string.Empty;
			}

			app.IsReviewedGuideline = this.rbReviewGuideLine.SelectedValue == "1";
			app.OtherSite = this.tbOtherLocation.Text.Trim();
			//app.OtherCountry = this.tbOtherCountry.Text.Trim();
			app.RequesterNameEN = this.tbRequestorName.Text.Trim();
			if(this.tbRequestedDateFrom.Text!="")
			{
				app.RequestedDateFrom = Convert.ToDateTime(this.tbRequestedDateFrom.Text);
			}
			if(this.tbRequestedDateTo.Text!="")
			{
				app.RequestedDateTo = Convert.ToDateTime(this.tbRequestedDateTo.Text);
			}

			if(this.tbAlternateDateFrom.Text != string.Empty)
				app.AlternateDateFrom = Convert.ToDateTime(this.tbAlternateDateFrom.Text);
			if(this.tbAlternateDateTo.Text != string.Empty)
				app.AlternateDateTo = Convert.ToDateTime(this.tbAlternateDateTo.Text);

			IUser userService = AppContainer.Instance[ServiceConst.UserService] as IUser;
//			app.RequesterNo = userService.GetUser(HttpContext.Current.User.Identity.Name);
			app.RequesterNo = userService.GetUser(app.RequesterNameEN);
			app.RequestDate = this.RequestDate;
			
			// Apply for someone else
			bool applyForSomeElse = this.rbSomeoneElse.SelectedValue == "1";
			app.ApplyForSomeoneElse = applyForSomeElse;
			if(applyForSomeElse)
			{
				if(this.SearchStaff.EmployeeName == string.Empty)
				{
					Page.RegisterClientScriptBlock("","<script>alert('Name of someone else should be specified.');</script>");

					return ;
				}
				if(this.SearchStaff.EmployeeName != string.Empty)
				{
					app.DepartmentName = this.GetUser(this.SearchStaff.EmployeeName).Department;
					app.SomeoneElseNo = this.GetUserById(this.SearchStaff.EmployeeID);
					app.SomeoneElseNameEN = this.SearchStaff.EmployeeName;
				}
				app.SomeoneElseHRID = this.Ctl_HRID.Text.Trim();
				app.SomeoneElseTel = this.tbSomeoneTel.Text.Trim();
				app.SomeoneElseMobil = this.Ctl_SomeoneMobil.Text.Trim();
				app.SomeoneElseEmail = this.tbSomeoneEmail.Text.Trim();
			}
			else
			{
				app.DepartmentName = this.GetUser(app.RequesterNameEN).Department;

				app.SomeoneElseHRID = string.Empty;
				app.SomeoneElseNo = null;
				app.SomeoneElseNameEN = string.Empty;
				app.SomeoneElseTel = string.Empty;
				app.SomeoneElseMobil = string.Empty;
				app.SomeoneElseEmail = string.Empty;
			}

			// Customer Info
			customer.Id = this.CustomerID;
			customer.Company = this.tbCustomerName.Text.Trim();
			customer.IsFCPA = this.rbIsFCPA.SelectedValue == "1";
			customer.Country = this.tbCustomerCountry.Text.Trim();
//			customer.NumberOfPerson = this.tbGuestNumber.Text.Trim();
			customer.VisitObjective = this.tbVisitObjectives.Text.Trim();

			if(WebUtility.IsNumber(this.tbPotentialRevenue.Text))
			{
				customer.DecryptedRevenuePotential = Convert.ToDecimal(this.tbPotentialRevenue.Text);
			}
			if(this.ddlPotentialRevenueTime.SelectedItem!=null)
			{
				customer.PotentialRevenueTimeframe = Convert.ToInt32(this.ddlPotentialRevenueTime.SelectedValue);
			}
			if(this.ddlSaleStage.SelectedItem!=null)
			{
				customer.SalesStage = Convert.ToInt32(this.ddlSaleStage.SelectedValue);
			}

			bool ISRFP = this.rbOutStandingRFP.SelectedValue == "1";
			customer.IsInRFP = ISRFP;
			if(ISRFP)
			{
				customer.RFPDetail = this.Ctl_RFPDetails.Text;
			}
			else
			{
				customer.RFPDetail = string.Empty;
			}
			bool ISSensiveIssue = this.RB_IsSensitiveIssue.SelectedValue == "1";
			customer.IsSensitiveIssue = ISSensiveIssue;
			if(ISSensiveIssue)
			{
				customer.IsThereSensitiveIssue = this.tbSensitiveIssues.Text;
			}
			else
			{
				customer.IsThereSensitiveIssue = string.Empty;
			}
			bool ISKEYMessage = this.RB_IsSensitiveIssue.SelectedValue == "1";
			customer.IsKeyMessage = ISKEYMessage;
			if(ISKEYMessage)
			{
				customer.IsThereKeyMessage = this.tbKeyMessage.Text;
			}
			else
			{
				customer.IsThereKeyMessage = string.Empty;
			}

			customer.CompanyProfile = this.tbCompanyProfile.Text.Trim();
			customer.AccountType = new DicItem();
			if(this.ddlAccountType.SelectedItem!=null)
			{
				customer.AccountType.Id = Convert.ToInt32(this.ddlAccountType.SelectedValue);
			}
			customer.ProposalNo = this.tbProposalNo.Text.Trim();

			// BusinessPurpose
			business.Id = this.BusinessID;
			bool ISContract = this.rbSalesContract.SelectedValue == "1";
			business.IsInSalesContract = ISContract;
			if(ISContract)
			{
				bool ISSIGNED = this.rbSalesContractSigned.SelectedValue == "1";
				business.IsContractSigned = ISSIGNED;
				if(ISSIGNED)
				{
					// Contract Info
					DataTable contracttable = (DataTable)this.dgContractInfo.DataSource;
					if(contracttable != null && contracttable.Rows.Count > 0)
					{
						for(int i=0;i<contracttable.Rows.Count;i++)
						{
							ContractInfo ci = new ContractInfo();
							ci.DateOfContract = Convert.ToDateTime(contracttable.Rows[i]["DateOfContract"]);
							ci.ContractNo = contracttable.Rows[i]["ContractNo"].ToString();
							ci.ProducstSold = contracttable.Rows[i]["ProducstSold"].ToString();
							ci.VisitPurposeInContract = contracttable.Rows[i]["VisitPurposeInContract"].ToString();
							ci.Quotas = Convert.ToInt32(contracttable.Rows[i]["Quotas"]);
							ci.UnitPrice = Convert.ToDecimal(contracttable.Rows[i]["UnitPrice"]);
							ci.Budget = Convert.ToDecimal(contracttable.Rows[i]["Budget"]);
			
							contract.Add(ci);
						}
					}
				}
			}
			else
			{
				business.IsContractSigned = false;
				business.Opportunities = this.tbNotSalesContractDescription.Text;
				business.Itinerary = this.tbNotSalesContractDescription.Text;
			}

			//business.IsContractSigned = this.rbSalesContractSigned.SelectedValue == "1";

			bool ISACTIVITY = this.rbActivityInTrip.SelectedValue == "1";
			business.RecreationalActivity = ISACTIVITY;
			if(ISACTIVITY)
			{
				business.Itinerary = this.Ctl_DetailedItinerary.Text;
			}
			else
			{
				business.Itinerary = string.Empty;
			}

			// Topic 
			topic.Id = this.TopicID;
			topic.TopicName = this.tbTopic.Text.Trim();

			// SalesTeam
			salesTeam.Id = this.SalesTeamID;
			salesTeam.HostNameEN = this.tbCustomerTeamHost.Text.Trim();
			salesTeam.OfficeTel = this.tbCustomerOfficeTel.Text.Trim();
			salesTeam.OfficeFax = this.tbCustomerFax.Text.Trim();
			salesTeam.Email = this.tbCustomerEmail.Text.Trim();
			if(this.ddlSalesBusinessUnit.SelectedItem!=null)
			{
				salesTeam.SalesBusinessUnit = this.ddlSalesBusinessUnit.SelectedValue;
			}
			if(this.ddlRegion.SelectedItem!=null)
			{
				salesTeam.Region = this.ddlRegion.SelectedValue;
			}

			// LogisticalInfo
			logist.Id = this.LogistID;

			logist.IsNeedHotel = this.rbHotelRequired.SelectedValue == "1";
			logist.HotelPreferences = this.tbHotelPreferences.Text;
			if(this.tbDatesRequiredFrom.Text != string.Empty)
				logist.DateRequiredFrom = Convert.ToDateTime(this.tbDatesRequiredFrom.Text);
			if(this.tbDatesRequiredTo.Text != string.Empty)
				logist.DateRequiredTo = Convert.ToDateTime(this.tbDatesRequiredTo.Text);
			if(WebUtility.IsNumber(this.tbPriceRangeFrom.Text))
				logist.DecryptedPriceFrom = Convert.ToDecimal(this.tbPriceRangeFrom.Text);
			if(WebUtility.IsNumber(this.tbPriceRangeTo.Text))
				logist.DecryptedPriceTo = Convert.ToDecimal(this.tbPriceRangeTo.Text);
			logist.IsNeedGroundTransportation = this.rbTransportationRequired.SelectedValue == "1";
			logist.IsNeedEntertainment = this.rbEntertainmentNeed.SelectedValue == "1";
			logist.EntertainmentPreference = this.tbPreferEntertainment.Text.Trim();
			if(WebUtility.IsNumber(this.tbEntertainmentPriceRangeFrom.Text))
				logist.DecryptedEntertainmentPriceFrom = Convert.ToDecimal(this.tbEntertainmentPriceRangeFrom.Text);
			if(WebUtility.IsNumber(this.tbEntertainmentPriceRangeTo.Text))
				logist.DecryptedEntertainmentPriceTo = Convert.ToDecimal(this.tbEntertainmentPriceRangeTo.Text);
			logist.IsNeedGift = this.rbGiftNeed.SelectedValue == "1";
			logist.GiftPreference = this.tbPreferGift.Text;
			if(WebUtility.IsNumber(this.tbGiftPriceRangeFrom.Text))
				logist.DecryptedGiftPriceFrom = Convert.ToDecimal(this.tbGiftPriceRangeFrom.Text);
			if(WebUtility.IsNumber(this.tbGiftPriceRangeTo.Text))
				logist.DecryptedGiftPriceTo = Convert.ToDecimal(this.tbGiftPriceRangeTo.Text);
			logist.IsReceivedALGiftBefore = this.rbReceivedGift.SelectedValue == "1";
			logist.IsNeedInterpreter = this.rbInterpreterRequired.SelectedValue == "1";
			logist.InterpretionType = Convert.ToInt32(this.rbSimultaneousConsecutive.SelectedValue);
			logist.SpecialDialect = this.rbSpecialDialect.SelectedValue;

			logist.TravelAgency = this.tbTravel.Text.Trim();



			// Payment Info
			payment.Id = this.PaymentID;
			payment.Payer = Convert.ToInt32(this.ddlPayingFor.SelectedValue);
			payment.IsPayServiceProvider = this.rbDirectToProvider.SelectedValue == "1";
			payment.NotDirectPayReasons = this.tbNotDirectReason.Text.Trim();
			if(this.tbEstimateTotalCost.Text != string.Empty)
				payment.DecryptedEstimatedCustomerTotalCost = Convert.ToDecimal(this.tbEstimateTotalCost.Text);
			if(this.tbEstimateCostPerPerson.Text != string.Empty)
				payment.DecryptedEstimateCustomerdIndividualCost = Convert.ToDecimal(this.tbEstimateCostPerPerson.Text);
			payment.CustomerPerdiem = this.tbReason.Text.Trim();

			// site info
//			for(int i=0;i<this.cblPreferredLocation.Items.Count;i++)
//			{
//				if(cblPreferredLocation.Items[i].Selected)
//				{
//					AppVisitingSite appSite = new AppVisitingSite();
//					appSite.Site = new DicItem();
//					appSite.Site.Id = Convert.ToInt32(cblPreferredLocation.Items[i].Value);
//
//					site.Add(appSite);
//				}
//			}

			
            string VenueInfo = this.tbOtherLocation.Text;
			app.OtherSite = VenueInfo;
			customer.Venue = VenueInfo;

			// Customer Attendee Info
			DataTable table = (DataTable)this.dgCustomerList.DataSource;
			if(table != null && table.Rows.Count > 0)
			{
				for(int i=0;i<table.Rows.Count;i++)
				{
					CustomerAttendee cus = new CustomerAttendee();
					cus.NameEN = table.Rows[i]["Name"].ToString();
					cus.Title = table.Rows[i]["Title"].ToString();
					cus.Company = table.Rows[i]["Company"].ToString();
					cus.NameCN= table.Rows[i]["NameCN"].ToString();
					cus.TitleEN = table.Rows[i]["TitleEN"].ToString();
					cus.CompanyEN = table.Rows[i]["CompanyEN"].ToString();

					cus.Responsibility = new DicItem();
					cus.Responsibility.Id =	Convert.ToInt32(table.Rows[i]["ResponsibilityID"]);
					cus.Affects = new DicItem();
					cus.Affects.Id = Convert.ToInt32(table.Rows[i]["AffectsID"]);
					cus.IsAttended = true;

					cus.Remark = table.Rows[i]["Remark"].ToString();
					cus.IsExisted = Convert.ToInt32(table.Rows[i]["IsExisted"]);

					customerAttendee.Add(cus);
				}
			}
			if(this.dgCustomerList.Items.Count>0)
			{
				customer.NumberOfPerson = this.dgCustomerList.Items.Count.ToString(); 
			}

			// AL Attendee Info
			table = (DataTable)this.dgALAttendee.DataSource;
			if(table != null && table.Rows.Count > 0)
			{
				for(int i=0;i<table.Rows.Count;i++)
				{
					ALAttendee al = new ALAttendee();
					al.EmployeeId = new Employee();
					al.EmployeeId.Id = table.Rows[i]["EmployeeId"].ToString();
					al.Title = table.Rows[i]["Title"].ToString();
			
					alAttendee.Add(al);
				}
			}
			// NEW UPDATE JOVI


			// Cost Center Info
			table = (DataTable)this.dgCostCenter.DataSource;
			if(table != null && table.Rows.Count > 0)
			{
				for(int i=0;i<table.Rows.Count;i++)
				{
					CostCenterRelatedCost co = new CostCenterRelatedCost();
					co.CostCenterCode = table.Rows[i]["CostCenterCode"].ToString();
					co.DecryptedCost = Convert.ToDecimal(table.Rows[i]["Cost"]);
					co.CostType = CostType.Budget;
			
					cost.Add(co);
				}
			}
		}
		#endregion

		#region ItemDataBound

		private void dgCustomerList_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
		{
			if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
			{
				ImageButton Btn_Edit = (ImageButton) e.Item.Cells[5].FindControl("Btn_Edit");
				string ItemId = e.Item.Cells[0].Text.ToString();
				Btn_Edit.Attributes.Add("onclick", "OpenCustomerPane('"+ItemId+"');");
				Btn_Edit.Attributes.Add("check", "false");

				ImageButton ld = (ImageButton)e.Item.Cells[6].FindControl("Btn_Delete");
				if(ld != null)
				{
					ld.Attributes.Add("onclick","On_Submit();");
					ld.Attributes.Add("check", "false");
				}

				string IsExisted = e.Item.Cells[7].Text.ToString();
				if(IsExisted==BEGDC.CC.BL.Common.CISFlag.NotExisted)
				{
					System.Web.UI.WebControls.Image WarningImg = (System.Web.UI.WebControls.Image) e.Item.Cells[8].FindControl("CISWarning");
					WarningImg.Visible = true;
				}
			}
		}
		
		private void dgALAttendee_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
		{
			if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
			{
				ImageButton Btn_Edit = (ImageButton) e.Item.Cells[3].FindControl("Btn_ALEdit");
				string ItemId = e.Item.Cells[0].Text.ToString();
				Btn_Edit.Attributes.Add("onclick", "OpenALAttendeePane('"+ItemId+"');");
				Btn_Edit.Attributes.Add("check", "false");

				ImageButton ld = (ImageButton)e.Item.Cells[3].FindControl("Btn_ALDelete");
				if(ld != null)
				{
					ld.Attributes.Add("onclick","On_Submit();");
					ld.Attributes.Add("check", "false");
				}
			}
		}

		
		private void dgCostCenter_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
		{
			if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
			{
				ImageButton Btn_Edit = (ImageButton) e.Item.Cells[3].FindControl("Btn_CostEdit");
				string ItemId = e.Item.Cells[0].Text.ToString();
				Btn_Edit.Attributes.Add("onclick", "OpenCostCenterPane('"+ItemId+"');");
				Btn_Edit.Attributes.Add("check", "false");

				ImageButton ld = (ImageButton)e.Item.Cells[3].FindControl("Btn_CostDelete");
				if(ld != null)
				{
					ld.Attributes.Add("onclick","On_Submit();");
					ld.Attributes.Add("check", "false");
				}
			}
		}

		private void dgContractInfo_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
		{
			if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
			{
				ImageButton Btn_Edit = (ImageButton) e.Item.Cells[8].FindControl("Btn_ContractEdit");
				string ItemId = e.Item.Cells[0].Text.ToString();
				Btn_Edit.Attributes.Add("onclick", "OpenContractPane('"+ItemId+"');");
				Btn_Edit.Attributes.Add("check", "false");
				ImageButton ld = (ImageButton)e.Item.Cells[8].FindControl("Btn_ContractDelete");
				if(ld != null)
				{
					ld.Attributes.Add("onclick","On_Submit();");
				}
			}
		}

		#endregion

		#region DeleteCommand
		private void dgContractInfo_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			try
			{
				if(Request.Form["cbDel"] == null || Request.Form["cbDel"] == "1")
				{
					return;
				}

				int rowid = Convert.ToInt32(e.Item.Cells[0].Text);
			
				DataTable contractInfo = (DataTable)Session[SessionFlag.ContractInfo];
				DataRow contractRow = contractInfo.Rows[rowid-1];
				contractInfo.Rows.Remove(contractRow);
				this.BindContractInfo();
			}
			catch
			{	
			}
		}

		private void dgCustomerList_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			try
			{
				if(Request.Form["cbDel"] == null || Request.Form["cbDel"] == "1")
				{
					return;
				}

				int rowid = Convert.ToInt32(e.Item.Cells[0].Text);
			
				DataTable contractInfo = (DataTable)Session[SessionFlag.CustomerSessionEZ];
				DataRow contractRow = contractInfo.Rows[rowid-1];
				contractInfo.Rows.Remove(contractRow);
				this.BindCustomerAttendee();
			}
			catch
			{	
			}
		}

		private void dgALAttendee_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			try
			{
				if(Request.Form["cbDel"] == null || Request.Form["cbDel"] == "1")
				{
					return;
				}

				int rowid = Convert.ToInt32(e.Item.Cells[0].Text);
			
				DataTable contractInfo = (DataTable)Session[SessionFlag.AccompanySessionEZ];
				DataRow contractRow = contractInfo.Rows[rowid-1];
				contractInfo.Rows.Remove(contractRow);
				this.BindALAttendee();
			}
			catch
			{	
			}
		}

		private void dgCostCenter_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			try
			{
				if(Request.Form["cbDel"] == null || Request.Form["cbDel"] == "1")
				{
					return;
				}

				int rowid = Convert.ToInt32(e.Item.Cells[0].Text);
			
				DataTable contractInfo = (DataTable)Session[SessionFlag.CostCenter];
				DataRow contractRow = contractInfo.Rows[rowid-1];
				contractInfo.Rows.Remove(contractRow);
				this.BindCostCenter();
			}
			catch
			{	
			}
		}
		#endregion

		#region Select Change

//		private void rbDomesticOversea_SelectedIndexChanged(object sender, System.EventArgs e)
//		{
//			if(this.rbDomesticOversea.SelectedValue == DOMESTIC)
//				WebUtility.BuildCheckBoxList(this.cblDomesticOversea,BEGDC.CC.BL.Common.DicType.Domestic);
//			else
//				WebUtility.BuildCheckBoxList(this.cblDomesticOversea,BEGDC.CC.BL.Common.DicType.Oversea);	
//		}

		private void rbSomeoneElse_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			this.litScript.Visible = true;
			if(this.rbSomeoneElse.SelectedValue == "1")
				this.litScript.Text = "<script>showpart2(1);</script>";
			else
				this.litScript.Text = "<script>showpart2(0);</script>";
		}

		private void Contract_Select(object sender, System.EventArgs e)
		{
			if(this.rbSalesContractSigned.SelectedValue == "1")
			{
				this.Table_Contract.Visible = true;
			}
			else
			{
				this.Table_Contract.Visible = false;
			}
		}
		#endregion

		#region CheckCustomer
		private bool CheckCISCustomer()
		{
			if(this.dgCustomerList.Items.Count==0) return false;
			foreach(DataGridItem row in this.dgCustomerList.Items)
			{
				string IsExisted = row.Cells[7].Text.ToString();
				if(IsExisted==BEGDC.CC.BL.Common.CISFlag.NotExisted)
				{
					return true;
				}
			}
			return false;
		}
		#endregion

		#region CATBranch_SelectChange
		private void CATBranch_SelectChange(object sender, System.EventArgs e)
		{
			IQuery query = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
			BEGDC.CC.Entity.Department dept = query.GetDepartmentByCode(this.Dp_Department.SelectedValue);
			
			if((dept!=null && (dept.DepartmentType.DicItemKey == BEGDC.CC.BL.Common.SysDicItem.DepartmentType.CAT)) || (this.Dp_Department.SelectedValue.ToString() == "OTH"))
			{
				this.TR_Account.Visible = false;
			}
			else
			{
				this.TR_Account.Visible = true;
			}
		}
		#endregion

		#region DisableCATBranchAcount
		public void DisableCATBranchAcount()
		{
			this.Dp_Department.Enabled = false;
			this.Dp_Account.Enabled = false;
		}
		#endregion



		#region Calculation Methods
		private string CalculateSum()
		{
			decimal sum = 0;
			DataTable table = (DataTable)this.dgContractInfo.DataSource;
			if(table != null)
			{
				for(int i=0; i<table.Rows.Count; i++)
				{
					sum += Convert.ToDecimal(table.Rows[i]["Quotas"]) * Convert.ToDecimal(table.Rows[i]["UnitPrice"]);
				}
			}

			return sum.ToString("0.00");
		}

		private string CalculateCostSum()
		{
			decimal sum = 0;
			DataTable table = (DataTable)this.dgCostCenter.DataSource;
			if(table != null)
			{
				for(int i=0; i<table.Rows.Count; i++)
				{
					sum += Convert.ToDecimal(table.Rows[i]["Cost"]);
				}
			}

			return sum.ToString("0.00");
		}
		#endregion

		#region Show Export Icon
		public void ShowExport()
		{
			this.ctrlExport.Visible=true;
		}
		#endregion

		#region Modify
		public void ShowModifyStatus()
		{
			BindCustomerAttendee();
			BindALAttendee();

			this.CustomerPaneImg.Visible = true;
			this.ALPaneImg.Visible = true;
			this.tbRequestedDateFrom.Visible = true;
			this.tbRequestedDateTo.Visible = true;
			this.RequestedDateFromspan.Visible = true;
			this.tbRequestedDateToSpan.Visible = true;
			this.lbRequestedDateFromReadOnly.Visible = false;
			this.lbRequestedDateToReadOnly.Visible = false;

			this.dgCustomerList.Columns[6].Visible = true;
			this.dgALAttendee.Columns[3].Visible = true;
		}

		public void EndModifyStatus()
		{
			Session[SessionFlag.CustomerSessionEZ] = null;
			Session[SessionFlag.AccompanySessionEZ] = null;

			this.ALPaneImg.Visible = false;
			this.CustomerPaneImg.Visible = false;
			this.tbRequestedDateFrom.Visible = false;
			this.tbRequestedDateTo.Visible = false;
			this.RequestedDateFromspan.Visible = false;
			this.tbRequestedDateToSpan.Visible = false;
			this.lbRequestedDateFromReadOnly.Visible = true;
			this.lbRequestedDateToReadOnly.Visible = true;
			this.lbRequestedDateFromReadOnly.Text = this.tbRequestedDateFrom.Text;
			this.lbRequestedDateToReadOnly.Text = this.tbRequestedDateTo.Text;

			this.dgCustomerList.Columns[6].Visible = false;
			this.dgALAttendee.Columns[3].Visible = false;
		}
		
		public void BuildModificationChange(ref Application app, ref IList customerAttendee, ref IList alAttendee)
		{
			if(this.tbRequestedDateFrom.Text!="")
			{
				app.RequestedDateFrom = Convert.ToDateTime(this.tbRequestedDateFrom.Text);
			}
			if(this.tbRequestedDateTo.Text!="")
			{
				app.RequestedDateTo = Convert.ToDateTime(this.tbRequestedDateTo.Text);
			}
			
			// Customer Attendee Info
			DataTable table = (DataTable)this.dgCustomerList.DataSource;
			if(table != null && table.Rows.Count > 0)
			{
				for(int i=0;i<table.Rows.Count;i++)
				{
					CustomerAttendee cus = new CustomerAttendee();
					cus.NameEN = table.Rows[i]["Name"].ToString();
					cus.Title = table.Rows[i]["Title"].ToString();
					cus.Company = table.Rows[i]["Company"].ToString();			
					cus.NameCN = table.Rows[i]["NameCN"].ToString();
					cus.TitleEN = table.Rows[i]["TitleEN"].ToString();
					cus.CompanyEN = table.Rows[i]["CompanyEN"].ToString();				
					cus.Responsibility = new DicItem();
					cus.Responsibility.Id =	Convert.ToInt32(table.Rows[i]["ResponsibilityID"]);
					cus.Affects = new DicItem();
					cus.Affects.Id = Convert.ToInt32(table.Rows[i]["AffectsID"]);
					cus.IsAttended = true;

					cus.Remark = table.Rows[i]["Remark"].ToString();
					cus.IsExisted = Convert.ToInt32(table.Rows[i]["IsExisted"]);

					customerAttendee.Add(cus);
				}
			}
//			if(this.dgCustomerList.Items.Count>0)
//			{
//				customer.NumberOfPerson = this.dgCustomerList.Items.Count.ToString(); 
//			}

			// AL Attendee Info
			table = (DataTable)this.dgALAttendee.DataSource;
			if(table != null && table.Rows.Count > 0)
			{
				for(int i=0;i<table.Rows.Count;i++)
				{
					ALAttendee al = new ALAttendee();
					al.EmployeeId = new Employee();
					al.EmployeeId.Id = table.Rows[i]["EmployeeId"].ToString();
					al.Title = table.Rows[i]["Title"].ToString();
			
					alAttendee.Add(al);
				}
			}
		}
		#endregion

	}
}

